# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/username/www$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ /\.ht {
deny all;
}
}
server { listen 80; ## listen for ipv4; this line is default and implied server_name yoursite.com ; root /home/username/www; index index.html index.htm index.php; error_log /var/log/nginx/yoursite.error.log warn; access_log /var/log/nginx/yoursite.access.log main; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { # This is cool because no php is touched for static content. # include the "?$args" part so non-default permalinks doesn't break when using query string try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/username/www$fastcgi_script_name; include fastcgi_params; fastcgi_intercept_errors on; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } location ~ /\.ht { deny all; } }此配置根据nginx官方的wordpress配置修改而来。注意其中的SCRIPT_FILENAME一行,此行缺少会导致PHP页面显示空白,但HTTP响应为没有错误的200,此行错误则会导致html显示正常,但php显示404找不到。
配置完成后启动nginx和php5-fpm。
sudo /etc/init.d/php5-fpm start sudo /etc/init.d/nginx start停止的方式类似:
sudo /etc/init.d/php5-fpm stop sudo /etc/init.d/nginx stop