Cache only static files in sub/subfolder but not sub

JoakimR nginx-forum at forum.nginx.org
Sun Feb 19 19:53:22 UTC 2017


Hi, I'm having as so many other a subfolder with media files, but I've like
to do a simple file caching of only one of the subfolders =
/media//thumbs/embedded with path insite the domain.tld and serve them as
media.domain.tld

So what I have done is added this to my config and it's working fine when I
out comments the second location directive, files are stored in the cache
and served as expected. 
Now the trouble shooting: as noticed above, this only works when I out
comments the second location, which is NOT to be cached at all. I have of
course tried to switch between which location comes first. Even chose I
recall it as first rule matching is served first.

Any one who can tell me why this isn't working as i like it to?

(for those who is curious, the location /thumbs/embedded holds about
4.200.000 files, where the rest is logically stored in same folder. The
other folders is divided into sub1/sub2/sub3/sub4/sub5, this one isn't)
  
  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;
    }

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



More information about the nginx mailing list