A 503 page gets written to my proxy cache, overwriting the 200

rge3 nginx-forum at nginx.us
Thu Jan 16 14:02:36 UTC 2014


Hi,

I'm trying to use the proxy cache to store regular pages (200) from my web
server so that when the web server goes into maintenance mode and starts
returning 503 nginx can still serve the good page out of cache.  It works
great for a few minutes but then at some point (5 to 10 minutes in) nginx
will overwrite the good 200 page in the cache with the bad 503 page and then
start handing out the 503.  Looking at my config I don't understand how a
503 could ever get written to cache but it is.  And the 200 page was brand
new (written 10 minutes before) so it shouldn't be the "inactive" time on
the proxy_cache_path setting causing nginx to delete the good file.  Can
anyone tell me what I'm missing?  Here are the relevant pieces of my
config:

        proxy_cache_path  /var/www/cache levels=1:2 keys_zone=my-cache:500m
max_size=3000m inactive=120h;
        proxy_temp_path /var/www/cache/tmp;
        proxy_cache_key "$scheme$host$request_uri";

        map $http_cookie $GotSessionCookie {
                default "";
                "~(?P<sessionid>\bSESS[^;=]+=[^;=]+)" $sessionid;
        }

        server {
                listen 80;
                server_name _;

                proxy_cache my-cache;

                location / {
                        proxy_pass http://production;
                        proxy_cache_valid  200 301 302  30m;
                        proxy_cache_valid  404 1m;
                }

                # don't cache pages with php's session cookie
                proxy_no_cache $cookie_$GotSessionCookie;

                # bypass the cache if we get a X-NoCache header
                proxy_cache_bypass $http_nocache $cookie_$GotSessionCookie;

                proxy_cache_use_stale http_500 http_503 error timeout
invalid_header updating;
        }

I can't imagine how a 503 would ever get cached given those
proxy_cache_valid lines but maybe I don't understand something.  Thanks for
any ideas!

-Rick

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,246507,246507#msg-246507



More information about the nginx mailing list