2

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.

6 Answers 6

3

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.

3

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.

1

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

0

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
1
  • 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, 2009 at 13:49
0

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

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .