Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

6 Answers 6

up vote 3 down vote accepted

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.

share|improve this answer

Yes there is, with Squid. Mark Nottingham worked on this at Yahoo, see this excellent blog post for all the details.

One thing, Squid 3.0 is a pretty big rewrite of the Squid codebase, so don't blindly deploy the newest version of Squid, but check first which versions of Squid have this functionality. It might not be ported forward to 3.0.

I think womble is right about Varnish and doing this via Varnish' VCL, but I have never configured something like this with Varnish, so I can't say.

share|improve this answer

2.1.0 introduced saint mode which works with grace: http://varnish-cache.org/wiki/VCLExampleSaintMode

share|improve this answer

A hack that should work: You could generate a cached page from time to time and configure a 503 handler to use the cached page.

Add/Modify as needed to your conf:

ErrorDocument 503 /my_cached_page.html
share|improve this answer
    
However, I would need to generate this page dynamically depending on the query, right? Unless you are advocating that I create my own caching mechanism, I would not be able to generate that page if the back-end is down. –  sybreon Sep 21 '09 at 13:49

Varnish has a feature called "grace" which allows you to assign a grace period during which the object will be preserved after the TTL has expired. If your backend goes down, Varnish serves the graced (stale) object.

Check it out:

http://varnish.projects.linpro.no/wiki/VCLExampleGrace

share|improve this answer

Yep; stale-if-error / max-stale is in Squid 2.7 and 2.HEAD, but not 3.x (yet).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.