3

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?

1 Answer 1

4

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:

location / {
  proxy_pass http://backend;
  proxy_cache_valid 168h;

  # Bypass cache with purgecache=true query string and save new response to proxy cache
  proxy_cache_bypass $arg_purgecache;

  # Bypass cache with "x-purge-cache: true" request header and save new response to proxy cache
  proxy_cache_bypass $http_x_purge_cache;

  # Bypass cache with "nocache=true" cookie and save new response to proxy cache
  proxy_cache_bypass $cookie_nocache;
}

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

2
  • proxy_cache_bypass? will it update the cache? I thought it is just not using cached response. Thank you I will try, problem in that I can do nothing with clients. Dec 28, 2018 at 11:51
  • As I wrote, yes, it'll update cached copy of the resource.
    – Tubeless
    Dec 28, 2018 at 12:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .