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

The cache module of nginx version 1.1.19 does not take the Vary header into account. This means that nginx will serve the same request even if the content of one of the fields specified in the Vary header has changed.

In my case I only care about the Accept-Language header, all the others have been taken care of.

How can I make nginx cache everything except responses that have a Vary header that contains Accept-Language?

I suppose I should have something like

location / {
    proxy_cache cache;
    proxy_cache_valid 10m;
    proxy_cache_valid 404 1m;

    if ($some_header ~ "Accept-Language") { # WHAT IS THE HEADER TO USE?
         set $contains_accept_language # HOW SHOULD THIS VARIABLE BE SET?

    proxy_no_cache $contains_accept_language

    proxy_http_version 1.1;
    proxy_pass http://localhost:8001;

but I do not know what is the variable name for "the Vary header received from the backend".

share|improve this question

As the relevant ticket has it, you have a few options:

  1. Add $http_accept_language to the ​cache key.
  2. proxy_no_cache $upstream_http_vary;
share|improve this answer
I do not want to cache things with $http_accept_language at all, so it is pointless to add it to the cache key. – gioele Sep 16 '12 at 9:50
Regarding proxy_no_cache, in my case all the responses have the Vary header, with that I would end up bypassing the cache for all the requests. Also, that ticked is outdated, in current nginx proxy_no_cache seems to require proxy_cache_bypass as well. – gioele Sep 16 '12 at 9:52

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.