Your main configuration file at /etc/nginx/nginx.conf
has some pitfalls and it shouldn’t be that complex. Let me share a simpler version for you to start with…
server {
server_name www.yourdomain.com;
# please replace the root path
# ex: /srv/www/mysite.com/public_html
root /path/to/wordpress/installation;
index index.php;
# please update the path to W3 Total Cache's configuration
# ex: /srv/www/mysite.com/public_html/nginx.conf
include /path/to/wordpress/installation/nginx.conf;
location ~* \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location / { try_files $uri $uri/ /index.php?$args; }
}
Depending on your setup, you may modify the above (or add a few more lines of code). For example, if you access your site with www
in front, then you might want to add another server
block like this…
server {
server_name yourdomain.com;
return 301 $scheme://www.yourdomain.com$request_uri;
}
Whenever you update your W3 Total Cache settings, please always remember to restart or reload your Nginx server. Otherwise, Nginx would still be serving the previous configurations from W3 Total Cache. (I like Apache here that supports on the fly processing of htaccess rules.)
The above configuration has been tested on CentOS, Ubuntu and Debian (latest versions) with the latest Nginx and PHP-FPM. It wouldn’t work, if Apache is used to serve PHP.
Hope this helps.