WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] W3 Total Cache - CSS & JS Minify Doesn't Work. The css and js files don't exist (19 posts)

  1. SysFailure0x5a
    Member
    Posted 7 months ago #

    Latest version of w3 total cache. Enabling css and or js minify breaks my theme. When I view the source and click the .js or .css file I get a 404 page. Clear cache does not work. I navigated to my web directory /var/www/wordpress/wp-content/cache/minify/ and the directory is empty.

    The directory is group writable.

    APC nor disk cache work. I've tried various setting including combine only and different processors like tidy/default, etc.

    http://wordpress.org/plugins/w3-total-cache/

  2. SysFailure0x5a
    Member
    Posted 7 months ago #

    I enabled minify debugging and found this error:

    W3 Total Cache error:It appears Minify URL rewriting is not working. Please verify that all configuration files are included in the configuration file

    I'm using nginx. I checked the nginx.conf file and w3 total cache did place the rewrite rules there.

    # BEGIN W3TC Minify core
    rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last;
    set $w3tc_enc "";
    if (-f $request_filename$w3tc_enc) {
        rewrite (.*) $1$w3tc_enc break;
    }
    rewrite ^/wp-content/cache/minify/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last;
    rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last;
    # END W3TC Minify core

    What is going on here??? Why doesn't this work?

  3. SysFailure0x5a
    Member
    Posted 7 months ago #

    Anyone? Still having this problem.... I deleted the nginx rewrite rules and w3 repopulated them. Still have the same problem.

  4. SysFailure0x5a
    Member
    Posted 7 months ago #

    Here is the entire nginx.conf file

    # BEGIN W3TC Minify cache
    location ~ /wp-content/cache/minify.*\.js$ {
        types {}
        default_type application/x-javascript;
        add_header Vary "Accept-Encoding";
    }
    location ~ /wp-content/cache/minify.*\.css$ {
        types {}
        default_type text/css;
        add_header Vary "Accept-Encoding";
    }
    location ~ /wp-content/cache/minify.*js\.gzip$ {
        gzip off;
        types {}
        default_type application/x-javascript;
        add_header Vary "Accept-Encoding";
        add_header Content-Encoding gzip;
    }
    location ~ /wp-content/cache/minify.*css\.gzip$ {
        gzip off;
        types {}
        default_type text/css;
        add_header Vary "Accept-Encoding";
        add_header Content-Encoding gzip;
    }
    # END W3TC Minify cache
    
    # BEGIN W3TC Browser Cache
    gzip on;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
    # END W3TC Browser Cache
    # BEGIN W3TC CDN
    location ~ \.(ttf|ttc|otf|eot|woff|font.css)$ {
       add_header Access-Control-Allow-Origin "*";
    }
    # END W3TC CDN
    # BEGIN W3TC Minify core
    rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last;
    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/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last;
    rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last;
    # END W3TC Minify core
  5. sjoerdvantilburg
    Member
    Posted 7 months ago #

    Same problem! Posted 4 weeks ago, no reaction.....
    website: http://beneteau-outboard.nl

  6. almooj-craig
    Member
    Posted 7 months ago #

    If you look in your cache directory and the css an js files are not there, most likely you have a mod_rewrite problem.

    Until you get it sorted out, There is an option in the Minify section that does not use mod_rewrite to create the files, it directly calls the minify.php file.

    ----
    Rewrite URL structure
    If disabled, CSS and JS embeddings will use GET variables instead of "fancy" links.
    ----

    If after unchecking that box the files start showing up in your cache directory then you know that W3TC can create the files and write them.

    When you check that option, mod_rewrite will point to the minify.php file.

    RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L]

    So basically you need to make sure that your server is processing the .htaccess file and that it's there. If you don't process .htaccess files then it needs to be in your virtual host, same with ngnix.

    Craig

  7. SysFailure0x5a
    Member
    Posted 7 months ago #

    If you look in your cache directory and the css an js files are not there, most likely you have a mod_rewrite problem.

    almooj-craig, I'm using NGINX, not Apache. There is no .htaccess and no mod_rewrite. W3 has generated the NGINX rewrite rules for me, but they are not working. All of my other rewrite rules work fine.

    The cache directory is writable and I even tried chmod-ing my whole damn site to 777 at one point to test.

    I strongly believe there is something wrong with the plugin.

  8. almooj-craig
    Member
    Posted 7 months ago #

    I know you are using nginx, I was just talking generically about rewrite.

    I use nginx for static files and it works as long as you have the correct rewrite rules in the server and location of your config file.

    Did you try un-checking the Rewrite URL structure
    If disabled, CSS and JS embeddings will use GET variables instead of "fancy" links. box.

    That will tell you that the plugin works correctly but that somehow your rewrite in Apache or in your case nginx is not correct.

    Craig

  9. SysFailure0x5a
    Member
    Posted 7 months ago #

    Just an FYI, I don't have apache installed at all.

    When I disable the fancy links, it does work. However, this is not acceptable due to the query string which my cdn does not like to cache.

    Again, I'm using the rewrite rules that w3 generated for me. It places them in the nginx.conf which is the equivalent to the .htaccess file.

    rewrite ^/wp-content/cache/minify/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last;
    rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last;
  10. almooj-craig
    Member
    Posted 7 months ago #

    Once you confirm that the minify.php file is working correctly then you can switch back and let rewrite do the work.

    Did you put the code that W3TC generated into your config file?

    Here is a link to my ngnix.conf file that may help you get your rewrite configuration working correctly.
    http://wordpress.org/support/topic/prefer-gz-instead-of-gzip?replies=5

    Craig

  11. SysFailure0x5a
    Member
    Posted 7 months ago #

    The code is automatically placed into the .conf file just like it places it in the .htaccess for apache.

    I've probably click and unclicked and enabled and disabled every feature twice in the software and my web server. Un ticking and re-ticking the box has no effect, it breaks again when it's checked.

    I checked that link. Using their config file instead of mine had no change. All my other rewrites work perfectly fine. Pretty permalinks for example.

  12. almooj-craig
    Member
    Posted 7 months ago #

    When you uncheck that box, did you look in your cache files and see if the css and js files are there.

    Did you read through my configuration and the one that W3TC generated to see what the difference is?

    There must be something amiss with your ngnix configuration because mine works without a problem on several different WP installations.

  13. SysFailure0x5a
    Member
    Posted 7 months ago #

    There are no files in /cache/ or /cache/minify/

    I'll look at your config again later today.

  14. almooj-craig
    Member
    Posted 7 months ago #

    When I was first trying to configure W3TC, I noticed that if that checkbox was unchecked, then W3TC would generate the files in the following directory, because it used minify.php directly in the url.
    /wp-content/cache/minify/000000

    When the box was checked, the files were removed and then they are generated when the file isn't there by doing a rewrite that points to the minify.php file.

    Craig

  15. SysFailure0x5a
    Member
    Posted 7 months ago #

    Yeah, I don't believe I was getting files in that directory with it enabled or disabled. Well at any rate I have this fixed. I pretty much wiped my config and started completely over from scratch. Maybe a syntax error somewhere in the code that wasn't being logged... Not sure. Here is what I have now if anyone else is interested. It may not be perfect, but it works for me.

    This config works on my WordPress Multisite 3.6.1 with NGINX 1.4.2 on Ubuntu Server 13.04 with Varnish 3.0.4 in front of everything and W3 Total Cache 0.9.3 with Page Cache, Minify, and all the other nice features enabled. You will need to change 8080 to 80 if you don't have a caching server in front of nginx.

    /etc/nginx/nginx.conf

    user nginx;
    worker_processes 16; # Change this to your CPU/Core count
    pid /run/nginx.pid;
    
    events {
            worker_connections 1024;
            multi_accept on;
    }
    
    http {
    
            sendfile on;
            tcp_nopush on;
            keepalive_timeout 120;
            client_max_body_size 512M;
            server_tokens on;
    
            include /etc/nginx/mime.types;
            default_type application/octet-stream;
    
            access_log /var/log/nginx/access.log;
            error_log /var/log/nginx/error.log;
    
            gzip on;
            gzip_disable "msie6";
            gzip_vary on;
            gzip_comp_level 7;
            gzip_proxied any;
            gzip_buffers 16 8k;
            gzip_http_version 1.1;
            gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    
            include /etc/nginx/conf.d/*.conf;
            include /etc/nginx/sites-enabled/*;
    
    }

    /etc/nginx/sites-enabled/example.net

    server {
            server_name example.net *.example.net;
            listen 8080 default_server;  #remove default_server if not using multisite.
            server_name_in_redirect off; #disable if not using multisite.
            root /var/www/example.net;
            index index.php;
            charset utf-8;
    
            fastcgi_buffers 16 16k;
            fastcgi_buffer_size 32k;
    
            #error and log for just this domain
            access_log   /var/log/nginx/examplenet-access.log;
            error_log    /var/log/nginx/examplenet-error.log;
    
            location ~ \.php$ {
                    try_files $uri /index.php;
                    include /etc/nginx/fastcgi_params;
                    fastcgi_read_timeout 240;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_param SCRIPT_FILENAME /var/www/example.net$fastcgi_script_name;
    
            }
    
            location / { try_files $uri $uri/ /index.php?$args ;    }
            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; }
    
            location = /robots.txt { access_log off; log_not_found off; }
            location ~ /\. { deny  all; access_log off; log_not_found off; }
    
            rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
            rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    
            # START W3 TOTAL CACHE CONFIG
            # BEGIN W3TC Minify cache
            location ~ /wp-content/cache/minify.*\.js$ {
                    types {}
                    default_type application/x-javascript;
                    add_header Vary "Accept-Encoding";
            }
            location ~ /wp-content/cache/minify.*\.css$ {
                    types {}
                    default_type text/css;
                    add_header Vary "Accept-Encoding";
            }
    
            location ~ /wp-content/cache/minify.*js\.gzip$ {
                    gzip off;
                    types {}
                    default_type application/x-javascript;
                    add_header Vary "Accept-Encoding";
                    add_header Content-Encoding gzip;
            }
    
            location ~ /wp-content/cache/minify.*css\.gzip$ {
                    gzip off;
                    types {}
                    default_type text/css;
                    add_header Vary "Accept-Encoding";
                    add_header Content-Encoding gzip;
            }
            # END W3TC Minify cache
            # BEGIN W3TC Page Cache cache
    
            location ~ /wp-content/cache/page_enhanced.*html$ {
                    add_header Vary "Accept-Encoding, Cookie";
            }
    
            location ~ /wp-content/cache/page_enhanced.*gzip$ {
                    gzip off;
                    types {}
                    default_type text/html;
                    add_header Vary "Accept-Encoding, Cookie";
                    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/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl
            text/xml image/x-icon;
    
            # END W3TC Browser Cache
            # BEGIN W3TC Minify core
    
            rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last;
            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/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last;
            rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last;
    
            # 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 ($request_uri !~ \/$) {
            set $w3tc_rewrite 0;
            }
    
            if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
            set $w3tc_rewrite 0;
            }
    
            set $w3tc_enc "";
            if ($http_accept_encoding ~ gzip) {
            set $w3tc_enc _gzip;
            }
    
            if (!-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc") {
            set $w3tc_rewrite 0;
            }
    
            if ($w3tc_rewrite = 1) {
            rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc" last;
            }
            # END W3TC Page Cache core
    
    }
  16. almooj-craig
    Member
    Posted 7 months ago #

    I'm glad you got it working! Thanks for posting your config files, it's interesting to read other examples. I like how you use include /etc/nginx/sites-enabled/*;, I just got in the habit of putting everything in the config file, perhaps I'll change someday.

    I noticed that you use Varnish as a caching server. Does that seem to reduce a lot of load from Ngnix. In my configuration I use Ngnix without any PCP to serve out static files and then I allow Apache to do everything else. Do you think throwing Varnish into the mix would make it even more efficient?

    Craig

  17. SysFailure0x5a
    Member
    Posted 7 months ago #

    I kind of stole the /etc/nginx/sites-enabled from the apache way of doing things. You just create a symlink from /etc/nginx/sites-available or simply issue a "mv" command between the two to enable or disable sites. Good for maintenance and testing/swapping configs. I also host a few other domains so it helps keep things organized.

    Varnish wasn't really put in place to reduce load. Nginx is already very low on cpu and memory. So, since I have all this extra memory laying around Varnish can keep all cached and static files directly in RAM which is great. So images, txt and other static files, html, gzip, etc are kept in RAM if someone has accessed them before. I have my own dedicated server so I can spin up VPS's with decent amounts of memory. I've dedicated 512MB of RAM just for varnish caching, will add more if I start getting more traffic.

    It's also nice because it can load balance between two back ends. I could put Vanrish on it's on server and split my webs server into two app tiers and point varnish to both.

  18. SysFailure0x5a
    Member
    Posted 7 months ago #

    Marking as resolved.

  19. kirky
    Member
    Posted 1 month ago #

    For anyone else that might be having this issue, I just solved it for me (apache not nginx) and it was a file permission issue. See the answer from Kirk WSI (me) here: http://stackoverflow.com/questions/15605927/wordpress-and-the-w3-total-cache-minifier/22538291#22538291

Reply

You must log in to post.

About this Plugin

About this Topic