Support » Plugin: W3 Total Cache » Nginx Browser rewrite rules cause 404 errors in static files

  • Resolved BasicPro

    (@estudio-de-grabacion)


    Again, thanks for this great plugin!

    The browser cache rules cause 404 errors in static files when using alias.

    So, part of my config in /sites-available/ would be.

    location /masters1/ {
    			add_header Content-Disposition "attachment";
    			alias /masters1/;
    }

    And these rewrite rules cause my server to throw 404 errors when I search for those files (www.example.com/masters1/myfile)

    location ~ \.(css|htc|less|js|js2|js3|js4)$ {
        expires 31536000s;
        etag on;
        if_modified_since exact;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public";
        add_header X-Powered-By "W3 Total Cache/0.9.7";
        try_files $uri $uri/ $uri.html /index.php?$args;
    }
    location ~ \.(html|htm|rtf|rtx|svg|txt|xsd|xsl|xml)$ {
        expires 0s;
        etag off;
        if_modified_since exact;
        add_header Pragma "public";
        add_header Cache-Control "max-age=0, public";
        add_header X-Powered-By "W3 Total Cache/0.9.7";
        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|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|_ttf|wav|wma|wri|woff|woff2|xla|xls|xlsx|xlt|xlw|zip)$ {
        expires 31536000s;
        etag on;
        if_modified_since exact;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public";
        add_header X-Powered-By "W3 Total Cache/0.9.7";
        try_files $uri $uri/ $uri.html /index.php?$args;
    }
    location ~ \.(bmp|class|doc|docx|eot|exe|ico|webp|json|mdb|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|pot|pps|ppt|pptx|svg|svgz|swf|tif|tiff|ttf|ttc|_ttf|wav|wri|woff|woff2|xla|xls|xlsx|xlt|xlw)$ {
        etag off;
        if_modified_since off;
        try_files $uri $uri/ $uri.html /index.php?$args;
    }

    Obviously, if I remove the file extensions that I use in my alias then it works, but I use both audio and image files and I want to get the browser cache for images.

    Any ideas on how can I make this work?

    Regards

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support gidomanders

    (@gidomanders)

    The location where you specify the alias is an exact match, where the locations added for browser caching are regex matching. The The exact match won’t match for URLs like /master1/myfile, but it will match the browser cache, trying to look for the file in the normal docroot. I think you need this:

    
    location ~ /masters1/.* {
    	add_header Content-Disposition "attachment";
    	alias /masters1/;
    }
    

    But I cannot test it without access to your server, so you should play around and check on Google for NginX alias directory matching.

    BasicPro

    (@estudio-de-grabacion)

    Thanks again for your great help. Your code gave a 403 error. I was finally able to solve it with this rule.

    location ^~ /masters1 {
    	add_header Content-Disposition "attachment";
    	alias /masters1;
    			
    }
    Plugin Support gidomanders

    (@gidomanders)

    That’s great! Could you please mark this topic as resolved then?

    BasicPro

    (@estudio-de-grabacion)

    Of course, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Nginx Browser rewrite rules cause 404 errors in static files’ is closed to new replies.