Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to get W3 Total Cache to rewrite URLs to minified files. I've tried every tutorial I could find but I don't seem to be able to get it right. I keep getting a W3 Total Cache error saying this:

It appears Minify 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 main configuration fail (and that you have reloaded / restarted nginx).

My config files for nginx are as follows: nginx.conf in /etc/nginx/

user nginx;
worker_processes 2;

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

events {
        worker_connections 1024;
        multi_accept on;
}

http {
        include mime.types;
        default_type            application/octet-stream;
        access_log              off;
        sendfile                on;
        keepalive_timeout       20;
        client_max_body_size    15m;
        upstream php {
                server unix:/dev/shm/php-fpm-www.sock;
        }
        include /etc/nginx/conf.d/default.conf
}

This file links to /etc/nginx/conf.d/default.conf:

server {
        server_name mydomain.com www.mydomain.com;
        listen 8080;
        root /var/www/;
        index index.php index.html index.htm;

        include /var/www/nginx.conf;
        include /etc/nginx/conf.d/wp.conf;
}

This file itself links to /etc/nginx/conf.d/wp.conf which looks as follows:

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;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    try_files $uri @wordpress;
}

/etc/nginx/conf.d/default.conf also links to the nginx.conf file W3 Total Cache created in my Wordpress root folder, which looks as follows:

# BEGIN W3TC Minify cache
location ~ /wp-content/cache/minify.*\.js$ {
    types {}
    default_type application/x-javascript;
    expires modified 604800s;
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
    add_header Vary "Accept-Encoding";
    add_header Pragma "public";
    add_header Cache-Control "max-age=604800, public";
}
location ~ /wp-content/cache/minify.*\.css$ {
    types {}
    default_type text/css;
    expires modified 604800s;
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
    add_header Vary "Accept-Encoding";
    add_header Pragma "public";
    add_header Cache-Control "max-age=604800, public";
}
location ~ /wp-content/cache/minify.*js\.gzip$ {
    gzip off;
    types {}
    default_type application/x-javascript;
    expires modified 604800s;
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
    add_header Vary "Accept-Encoding";
    add_header Pragma "public";
    add_header Cache-Control "max-age=604800, public";
    add_header Content-Encoding gzip;
}
location ~ /wp-content/cache/minify.*css\.gzip$ {
    gzip off;
    types {}
    default_type text/css;
    expires modified 604800s;
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
    add_header Vary "Accept-Encoding";
    add_header Pragma "public";
    add_header Cache-Control "max-age=604800, public";
    add_header Content-Encoding gzip;
}
# END W3TC Minify cache
# BEGIN W3TC Page Cache cache
location ~ /wp-content/cache/page_enhanced.*html$ {
    expires modified 3600s;
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
    add_header Vary "Accept-Encoding, Cookie";
    add_header Pragma "public";
    add_header Cache-Control "max-age=3600, public";
}
location ~ /wp-content/cache/page_enhanced.*gzip$ {
    gzip off;
    types {}
    default_type text/html;
    expires modified 3600s;
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
    add_header Vary "Accept-Encoding, Cookie";
    add_header Pragma "public";
    add_header Cache-Control "max-age=3600, public";
    add_header Content-Encoding gzip;
}
# END W3TC Page Cache cache
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascri$
location ~ \.(css|htc|js|js2|js3|js4)$ {
    expires 604800s;
    add_header Pragma "public";
    add_header Cache-Control "max-age=604800, public";
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
}
location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
    expires 3600s;
    add_header Pragma "public";
    add_header Cache-Control "max-age=3600, public";
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
    try_files $uri $uri/ $uri.html /index.php?$args;
}
location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe$
    expires 604800s;
    add_header Pragma "public";
    add_header Cache-Control "max-age=604800, public";
   add_header Link "<$scheme://$host$uri>; rel=\"canonical\"";
    add_header X-Powered-By "W3 Total Cache/0.9.2.8";
}
# END W3TC Browser Cache
# BEGIN W3TC Minify core
rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/mini$
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
    set $w3tc_enc .gzip;
}
if (-f $request_filename$w3tc_enc) {
    rewrite (.*) $1$w3tc_enc break;
}
rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.ph$
# END W3TC Minify core
# BEGIN W3TC Page Cache core
set $w3tc_rewrite 1;
if ($request_method = POST) {
    set $w3tc_rewrite 0;
}
if ($query_string != "") {
    set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_swit$
    set $w3tc_rewrite 0;
}
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
    set $w3tc_enc _gzip;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc$
    set $w3tc_ext .html;
}
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.xml$w3tc_enc"$
    set $w3tc_ext .xml;
}
if ($w3tc_ext = "") {
  set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
    rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ext$w3tc_enc" $
}
# END W3TC Page Cache core
# BEGIN W3TC CDN
location ~ \.(ttf|otf|eot|woff)$ {
   add_header Access-Control-Allow-Origin "*";
}
# END W3TC CDN

During copy pasting from nano in my terminal some lines weren't entirely in screen, but these are all standard W3 Total Cache settings, I haven't touched them. They should be ok.

I've got my server setup with nginx on port 8080, varnish on port 80, php5-fpm and MySQL. If anyone can help me out on this, that would be amazing. If you need more info, config files, etcetera, please let me know.

share|improve this question

closed as off-topic by mrwweb, Johannes Pille, birgire, Pieter Goosen, ialocin Aug 29 at 8:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – mrwweb, Johannes Pille, birgire, Pieter Goosen, ialocin
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Did you restart / reload Nginx after saving the configuration in W3 Total Cache plugin? If Varnish caches 404 responses as well, then you may need to restart / reload Varnish too. –  Pothi Feb 15 '13 at 12:50
    
Yeah, started doing that after I read that nginx doesn't dynamically update its config. I restart varnish every time I restart nginx. –  Nick Rutten Feb 15 '13 at 12:52
    
If you disable minify, does disk-enhanced caching work? –  Pothi Feb 15 '13 at 13:00
    
You may probably want to disable all other modules, such as disk-enhanced page caching, browser caching, etc to isolate the issue. Nginx log and varnishlog may help you with the debugging too. –  Pothi Feb 15 '13 at 13:09
    
Minify seems to be working just fine on your site. :) –  Pothi Feb 15 '13 at 13:14

2 Answers 2

Create a file specifically for W3 Total Cache configuration for your site, in a location Nginx/PHP-FPM can write to. Include this file in your site's Nginx server configuration. Then on the General Settings page, under Miscellaneous provide the full path to this file in the "Nginx server configuration file path" field. W3TC will then know to write any Nginx rules it needs to this file.

Make your W3TC settings changes to reflect the configuration you'd like. Once you're happy with the settings, reload Nginx. Your W3TC configuration should now be working properly.

share|improve this answer

Just disable javascript minification. I did it for my site and it worked.

share|improve this answer

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