【问题标题】:install wordpress in osx with nginx and php failed使用 nginx 和 php 在 osx 中安装 wordpress 失败
【发布时间】:2013-09-23 22:19:10
【问题描述】:

问题解决了

我想安装 wordpress osx。

这些都是我做的。

  1. $ brew install nginx
  2. $ brew install --without-apache --with-fpm --with-mysql php55
  3. 下载最新的 wordpress.zip 并解压到 /var/www/wordpress_test
  4. 通过php-fpm -g /usr/local/var/run/php-fpm.pid运行php-fpm
  5. 像这样写 nginx 配置文件。

/usr/local/etc/nginx/nginx.conf

worker_processes  1;

error_log /usr/local/log/nginx/error.log;
pid        /usr/local/var/run/nginx.pid;

events {
    worker_connections  256;
}

http {
    include       /usr/local/etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /usr/local/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    #gzip  on;
    include /usr/local/etc/nginx/site-enabled/*;
}

/usr/local/etc/nginx/site-avaiable/wordpress_test

server {
    listen       8080;
    server_name  localhost;

    access_log  /usr/local/log/nginx/wordpress_test.access.log;
    error_log  /usr/local/log/nginx/wordpress_test.error.log;

    root   /var/www/wordpress_test;
    index  index.html index.htm index.php;

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass 127.0.0.1:9000;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    location ~ /\.ht {
        deny  all;
    }
}
  1. 创建符号链接/usr/local/nginx/site-available/wordpress_test 到`usr/local/nginx/site-enabled/wordpress_test
  2. 创建/var/www/wordpress_test/info.php 并在其中写入<?php phpinfo(); ?>

我可以通过访问http://localhost:8080/info.php 来查看 php 信息。 但是当我访问http://localhost:8080/index.php 时收到错误消息。

/usr/local/log/nginx/wordpress_test.error.log 没有发送任何消息。 /usr/local/log/nginx/wordpress_test.access.log 显示此消息。

127.0.0.1 - - [23/Sep/2013:17:21:55 +0900] "GET /index.php HTTP/1.1" 500 537 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36"

我该如何解决这个问题?接下来我应该检查什么?

-- 我从http://codex.wordpress.org/Nginx 添加了这样的设置,然后就可以了。

# WordPress single blog rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
    try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires max;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
    # Zero-day exploit defense.
    # http://forum.nginx.org/read.php?2,88845,page=3
    # Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
    # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine.  And then cross your fingers that you won't get hacked.
    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#   fastcgi_intercept_errors on;
    fastcgi_pass php;
}

【问题讨论】:

    标签: php wordpress macos nginx


    【解决方案1】:

    这似乎是您的 .htaccess 文件无法与 nginx 一起使用,您是否将 wordpress .htaccess 文件转换为 nginx 配置?

    请查看 url http://winginx.com/htaccess 获取 .htaccess 到 nginx conf 转换器。

    【讨论】:

      【解决方案2】:

      只需将新位置添加到您的 /usr/local/etc/nginx/site-avaiable/wordpress_test

      location / {
          try_files $uri /index.php$request_uri;
      }
      

      【讨论】:

      • 感谢您的回复。我添加设置并执行nginx -s reload。但它还没有工作。
      • 你是用 sudo 调用的吗?
      • 不,在 osx 中我不需要它。当我编辑问题时,我解决了问题。不过还是谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      • 2015-05-23
      相关资源
      最近更新 更多