Welcome! Log In Create A New Profile

Advanced

Nginx Caching - Return 301 Redirect if file size > 2MB

Posted by G.Ashburn 
Nginx Caching - Return 301 Redirect if file size > 2MB
February 28, 2015 04:35PM
Hello, everyone!

I have a rule in place that will proxy and cache a bunch of file extensions:

######

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
proxy_pass http://{backend_IPs_pool};
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
}

######

I need the proxy server to bypass the cache in case the file size is larger than 2MB. I believe the best way to achieve that would be by forwarding the request to the upstream through a 301 redirect so that I can save the extremely expensive bandwidth on the proxy server.

Any ideas?

Thank you very much!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 197
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready