Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have an Apache behind Nginx. Nginx is used to load balance between webservers and to cache static content. The only problem is, every time the web application is updated we have to completely clear Nginx cache (static file cache is set to quite a high value, some static files change often others not).

Is there a clever way to let Nginx periodically check that the file has been modified (note: Apache returns "Date" in response headers) since the time file had been cached by Nginx.

share|improve this question
Please provide the relevant nginx configuration. – mgorven Jul 12 '12 at 2:48
Related:… – Michael Hampton Jul 12 '12 at 3:11
You really should use a webserver as a webserver, and a caching proxy as a caching proxy. "Right tool for the job" and all that. – womble Jul 12 '12 at 3:23
up vote 4 down vote accepted

You'll have to write a script that periodically crawls your internal content that you want cached, and have the script crawl each URL that you update.

In the script, set an HTTP header (the actual header doesn't matter) and then use proxy_cache_bypass to force nginx to retrieve it from upstream.

Example: Your cache priming script sets the HTTP header X-Really-Get-It: true. In nginx.conf you will set:

proxy_cache_bypass $http_x_really_get_it;

nginx will fetch the file from upstream instead of from cache, and then cache the result.

If you are willing and able to use third party nginx modules, you can also use the cache_purge module. It seems rather poorly documented, though.

share|improve this answer
that sounds great, do you happen to have a script? :) – Alex Jul 12 '12 at 9:20

Just serve your content with the right caching information - this will solve the problem on your proxy and any ohers between you and the client, e.g.

cache-control: max-age=86400; s-maxage=3600

instructs browsers to cache for 1 day, but proxies should cache for 1 hour.

But a better solution is to use different URLs for updated content.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.