Nginx doesn't honor Cache-Control: no-cache _request_

Mirosław Jaworski mjaw at ikp.pl
Mon Aug 3 14:41:31 MSD 2009


Hello 

RFC2616 14.9.4 Cache Revalidation and Reload Controls
"End-to-end reload" 
[...]The server MUST NOT use a cached copy when responding to such a
request[...]

Such a request can be triggered from the browser by holding SHIFT
and using reload button; it's often used by web developers to get
uncached response from the original server. Unfortunately nginx seems
to ignore such request and answers from the cache.

Is it possible to make a quick workaround bypassing the cache for such
requests using some request header variable conditional if?

server {
        listen       127.0.0.1:8000;
        server_name  localhost;

        location / {
            proxy_pass         http://192.168.10.10:80/;
            proxy_redirect     off;

            if ($request_header !~ "Cache-Control: no-cache") {
              proxy_cache        one;
              proxy_cache_valid  200 1h;
            }
            proxy_pass_header  Set-Cookie;

            proxy_set_header Host             $host;
            proxy_set_header X-Real-IP        $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

?

-- 
Mirosław "Psyborg" Jaworski
GCS/IT d- s+:+ a C++$ UBI++++$ P+++$ L- E--- W++(+++)$ N++ o+ K- w-- O-
M- V- PS+ PE++ Y+ PGP t 5? X+ R++ !tv b++(+++) DI++ D+ G e* h++ r+++ y?
              "Friendship is like money, easier made than kept."






More information about the nginx mailing list