I have a problem, I have a server with video-files and nginx as a proxy cache server for office.
As far as most videos not changing it working good, but time to time a few videos changing (I mean they just overwrites files on the server after fixing some bugs or artifacts in video), but nginx could not see it and backs old cache according with
proxy_cache_valid 200 302 96h;
Is there any way to save cache valid time 96h but force nginx time to time revalidate cache from upstream?
Best Answer
Yes it is possible with proxy_cache_bypass directive. You can define query string, cookie or HTTP request header that will allow you to fetch desired resource directly from backend server (bypassing Nginx proxy cache) and save that same response to proxy cache for serving subsequent requests.
Here are a few examples:
proxy_cache_bypass will work with as long as cookie, query string or request header don't have empty value or "0".
For example, to purge certain video file with query string, you can simply access https://example.com/some/video.mp4?purgecache=true