I need to nginx proxy use cache if backend server down:
this is my configuration. but seems be nginx use cache without check backend server.
http {
# ...
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=tmpzone:10m inactive=60m;
proxy_cache_key "$scheme$request_method$host$request_uri";
server {
server_name _;
location / {
proxy_connect_timeout 5s;
proxy_read_timeout 5s;
proxy_cache tmpzone;
proxy_cache_valid 200 304 1d;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host 'www.example.com';
proxy_pass http://www.example.com;
}
}
}
Question is how can i bypass the proxy cache if backend server is up ? And when backend server is up my proxy server dont use cache at all.