Hi I installed w3 total cache on my nginx powered site, I'm having errors however. For example when I enable page caching disk:enhanced I get:

It appears Page Cache URL rewriting is not working. If using apache, verify that the server configuration allows .htaccess or if using nginx verify all configuration files are included in the configuration.

When I choose page caching disk:basic no error is displayed.

Here is the config for the server in /etc/nginx/nginx.conf:


If it makes any difference, I have multiple sites installed, all in /srv/www

I can see that W3 Total Cache is creating a separate nginx.conf for each website, e.g. /srv/www/mysite.com/public_html/nginx.conf and within it there are the rules of W3 Total Cache, pasted here: http://pastebin.com/dANPVMJk

I would like to have a setup that works for any number of websites I will add. Clients on my server need to be free to update their W3 Total Cache configuration as they wish without the server needing to be restarted. Also they might opt not to use the plugin at all.

  • My recommendation would be to install APC instead and use that for page caching rather than the disk. It's a bit faster, and less to configure. – EAMann Jun 5 '12 at 15:20

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;
     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.

  • Since I have more than one site on the server how should I modify the above to cater for all the sites? – urok93 Jun 7 '12 at 8:06
  • @drtanz If you name this file as yourdomain.com.conf, please copy this file to anotherdomain.com.conf. Then replace yourdomain.com with anotherdomain.com in three places. Then replace the /path/to/wordpress/installation/. If you use W3 Total Cache in anotherdomain.com too, then replace /path/to/wordpress/installation/nginx.conf too. You may automate this (via a bash script or using a sed command) for any number of sites. – Pothi Kalimuthu Jun 8 '12 at 5:37
  • Can you tell me why this post (john-dugan.com/setup-w3tc-nginx) wraps the include into the location and not into server? – Jan Apr 4 '18 at 20:37
  • No idea. I haven't used W3TC for years. – Pothi Kalimuthu Apr 5 '18 at 7:10

You need to set the path to your .conf file in the plugin general options then let W3 Total write to the file.

I would create a w3-total.conf file in /etc/nginx then chown it www-data:www-data so w3 can write to it then add it as an include in your server file.


To answer your additional questions. If all your sites are using the same W3 Total Cache settings give them all the same path to the configuration file and include it inside all your server blocks.

For simplification I like to keep all my server blocks in 1 file then include a global wp.conf and a global w3-total.conf.

server {
   listen 80; 
    server_name domain1.com www.domain1.com;
    root /srv/www/domain1;
    index index.php index.html index.htm;

    include w3-total.conf;
    include wp.conf;    
server {
   listen 80; 
    server_name domain2.com www.domain2.com;
    root /srv/www/domain2;
    index index.php index.html index.htm;

    include w3-total.conf;
    include wp.conf;    


error_page 404 = @wordpress;
log_not_found off;

location / {
    try_files $uri $uri/ /index.php?$args;

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

location @wordpress {
    fastcgi_pass php;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_NAME /index.php;

location ~ \.php$ {
    fastcgi_max_temp_file_size 1M;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_index  index.php;
    fastcgi_pass php;  // php is defined in nginx.conf
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    try_files $uri @wordpress;


user www-data;
worker_processes  8;

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

events {
    worker_connections  1024;

http {
    include mime.types;
    default_type       application/octet-stream;
    access_log         /var/log/nginx/access.log;
    sendfile           on;
    keepalive_timeout  3;
    client_max_body_size 13m;
    # Upstream to abstract backend connection(s) for PHP.
    upstream php {
        server unix:/var/run/php5-fpm.sock;  //Make sure your setup to use sockets in /etc/php5/fpm/pool.d/www.conf

    include sites-enabled/*;

The above configuration is for a small Debian Squeeze VPS running php-fpm 5.4 and Nginx 1.2.0

  • ok I've created w3-total.conf in /etc/nginx, alongside nginx.conf. I also chowned it, and I can see the plugin is now writing stuff to this file. As I understand the last step would be to include it in nginx.conf, can you tell me how to do that? – urok93 Jun 4 '12 at 12:30
  • @drtanz You may include it at the top of all other location directives and other rewrite rules. If included in the middle or at the bottom of the rules (or location directives), W3 Total Cache plugin may still complain (aka show the same error). You may include it like include /path/to/w3-total.conf/;. – Pothi Kalimuthu Jun 5 '12 at 11:25
  • I get a location not allowed here in /etc/nginx/w3-total.conf:2 when I add the include under the http seciton in nginx.conf – urok93 Jun 5 '12 at 13:09
  • I've edited the initial question, maybe I hadn't explained my problem well enough initially. Let me know if you have any further solutions I can try. – urok93 Jun 5 '12 at 13:20
  • You may include the W3 Total Cache's configuration file only in the server section. Please check my answer below for a simpler version of /etc/nginx/nginx.conf file. Please note you'd still need http section in that file. HTH. – Pothi Kalimuthu Jun 5 '12 at 19:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.