Cache only static files in sub/subfolder but not sub

JoakimR nginx-forum at forum.nginx.org
Wed Feb 22 16:01:02 UTC 2017


Hi Francis

You're right I have overseen the ^~ for the location.

So for others, the solution to "force" the location directives is..


location ^~ /thumbs/embedded {
add_header X-Served-By "IDENT1";
add_header Cache-Control public;
add_header Pragma 'public';
add_header X-Cache-Status $upstream_cache_status;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
error_page 404 = /image404.php;
proxy_pass http://127.0.0.1:9001;
}

##Match what's not in above location directive
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
#access_log on;
#log_not_found on;
aio on;
sendfile on;
expires max;
add_header Cache-Control public;
add_header Pragma 'public';
add_header X-Served-By "IDENT2";
#add_header X-Frame-Options SAMEORIGIN;
error_page 404 = /image404.php;
} 


The quick view is that
location /thumbs/embedded {

change into

location ^~ /thumbs/embedded {

Pretty cool actually :)

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,272506,272563#msg-272563



More information about the nginx mailing list