Cache as failover

mfeldheim nginx-forum at nginx.us
Mon Dec 21 21:11:59 MSK 2009


Thank you, this is working excellent..
I've set the proxy_cache_valid to 10m to soften the I/O overhead.. still - would be cool if I could set
the cache TTL to a way higher value and bypass the caching completely while the backend servers return valid codes.

When backends fail and I have to deliver from cache, additionally I'd like to send a header "304 Not modified" ( does that make sense, since it is true..!? )

For those who might have a similar scenario..

Content backend servers fail, backup servers fail => deliver cache built on the Nginx proxy
search backend fails => no backup => deliver "503 Service Unavailable" maintainance site


upstream contentBackend {
        server 192.168.50.101 weight=2 max_fails=1  fail_timeout=30s;
        server 192.168.50.102 weight=2 max_fails=1  fail_timeout=30s;
        server 192.168.50.103 weight=2 max_fails=1  fail_timeout=30s;
        server 192.168.50.104 weight=2 max_fails=1  fail_timeout=30s;
        server 192.168.50.105 weight=2 max_fails=1  fail_timeout=30s;
        server 192.168.50.106 weight=1 max_fails=1  fail_timeout=30s;
        server 192.168.50.107 weight=1 max_fails=1  fail_timeout=30s;
        server 192.168.50.108 weight=1 max_fails=1  fail_timeout=30s;
        server 192.168.50.109 backup;
        server 192.168.50.110 backup;
}

upstream searchBackend {
        server 192.168.50.106 weight=1 max_fails=1  fail_timeout=30s;
        server 192.168.50.107 weight=1 max_fails=1  fail_timeout=30s;
        server 192.168.50.108 weight=1 max_fails=1  fail_timeout=30s;
}

proxy_ignore_headers    "Cache-Control" "Expires";
proxy_hide_header       "Set-Cookie";
proxy_cache_key         "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
proxy_cache_valid       200 302 301 304 1s;
proxy_cache_valid       any 0m;
proxy_cache_use_stale   error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_cache_path        /tmp/nginxCache levels=2:2 keys_zone=cache:256m inactive=7d max_size=65536m;

server {

        server_name _;

        location / {

                proxy_pass http://contentBackend;
                proxy_cache cache;
        }

        # no sense to deliver cached search masks, search wont work without a backend
        location /search/ {

                proxy_pass http://searchBackend;
                error_page 500 502 503 504 =510 /510.html;
        }

        location /510.html {
                root /srv/www/nginx/htdocs;
        }
}


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




More information about the nginx mailing list