I have nginx as a reverse proxy to a remote web server. Cache is written to file. However, when I place Varnish in front of it, nginx stops writing to cache file, which causes a performance hit and it doubles the traffic.

How it is possible that a front-end (Varnish) can tell nginx not to cache those requests? I tried to debug but not found anything. My nginx configuration is something like this:

server {
  location / {
    proxy_ignore_headers Set-Cookie Expires Cache-Control;
    proxy_cache p-cache;

Again, if I make direct request to nginx, there is no problem. But I have to use Varnish which is the unique door to other service to that server.

  • Some additional information, such as your Varnish config, might be helpful. However, two guesses - 1) Adding a front end server causes requests to originate from that IP (e.g. - since some caching and scripts depend on the IP - ensure it is set correctly. 2) Varnish can change the request sent to the backend (e.g. modifying headers, stripping cookies, etc - watch some requests reaching the backend with varnishlog to see what is making it through). – cyberx86 Jan 31 '12 at 20:31
  • I've found the problem. See my answer below. About cookies, headers... I already ignore all them in the conf that I posted above. This is my set up for edge side caching of media content, so I don't care about IP address, cookie, user agent etc. – jcisio Jan 31 '12 at 21:43

I've found it. It is because of proxy_cache_min_uses = 3 that I set in another place. With this declarative, nginx won't cache to file when there are less than 3 hits on the same url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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