0

Is there a way to specify a weight for a backend in Varnish? I need to be able to serve different page if my main backend is unaccessable.

alexus
  • 13,112
  • 32
  • 117
  • 174

1 Answers1

1

If you have varnish in front of a single backend, you can define the 503 page that is displayed when the backend isn't reachable. You could increase your grace time so that you serve old content if the backend fails.

If you have varnish in front of two backends, you can define a director with healthchecks that will remove the bad backend, leaving the other backend responding.

You can also intercept the 503 to report a page from a separate backend that has a static page. The directors don't really support weights, but since VCL is just compiled C code, there really isn't much you can't do. You can see if the beresp object is an error and select a different backend, perhaps the one for your error message.

Unless you're running varnish in front of a webfarm, putting the 503 page in Varnish is probably the easiest.

karmawhore
  • 3,865
  • 18
  • 9
  • I've tried going with director and I intentionally brought one of the backends down, yet varnish still serving content from backend that isn't responding. unless i didn't do it right inside of default.vcl configuration file. I even gave 1 weight to backend that I want to serve just 503 page and 10 to my real website. Where can I find a good example for creating 503 custom page? – alexus Oct 13 '10 at 21:42
  • http://www.varnish-cache.org/docs/2.1/tutorial/advanced_backend_servers.html has some snippets that you can use. Then you could define a known-good backend, and check req.backend.healthy and set the backend to your failmessage backend. – karmawhore Oct 13 '10 at 21:46