在OSX中使用nginx和PHP安装WordPress失败


install wordpress in osx with nginx and php failed

问题已解决

我想安装 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 by php-fpm -g /usr/local/var/run/php-fpm.pid
  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-availableable/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(); ?>.

我可以通过访问 php 信息来查看 http://localhost:8080/info.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;
}

这似乎是您的.htaccess文件不适用于nginx,您是否将wordpress .htaccess文件转换为nginx配置?

请参阅 网址 http://winginx.com/htaccess 的 .htaccess to nginx conf 转换器。

只需在/usr/local/etc/nginx/site-avaiable/wordpress_test中添加一个新位置

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