Web-server – Fail-over caching reverse proxy

cachereverse-proxyvarnishweb-server

Is there a way to configure varnish or any other caching reverse proxy, to serve pages from its cache when the back-end fails? At the moment, if the back-end goes down a 503 Service Unavailable error would be returned to the browser. I would prefer it if visitors got to see a cached version than an error page while the back-end is being fixed.

My setup:

[varnish (public ip)] <===> [router] <===> [web server (private ip)]

PS: I have only one back-end web server.

Best Answer

In theory, if an object is out-of-date, you don't want it served by the cache -- if it isn't out-of-date, the expiry should be set longer...

On the other hand, Varnish recognises that theory and practice diverge, so there's the grace directive in VCL that I think handles this case as well as the more prosaic uses documented in that page.