Trying multiple backends for a resource

Hugo Cisneiros (Eitch) hugo.cisneiros at gmail.com
Wed Aug 1 22:04:10 CEST 2012


On Wed, Aug 1, 2012 at 4:04 PM, Oddur Snær Magnússon <oddur at ccpgames.com> wrote:
> I´ve got multiple backends which each might have the file I´m requesting.
>
> Would it be possible to configure varnish in such a way that is tries multiple backends and uses the first one it finds with a 200 response ?

Maybe using restarts...

sub vcl_recv {
  if (req.http.fallbackmarker) {
    if (req.restarts == 1) {
      set req.backend = backend_one;
    } elsif (req.restarts == 2) {
      set req.backend = backend_two;
    } elsif (req.restarts == 3) {
      set req.backend = backend_two;
    }
    [...]
  }
}

sub vcl_fetch {
  if (req.url == "/file.ext" && beresp.status != 200) {
    set req.http.fallbackmarker = 1;
    return (restart);
  }
}

And setting option max_restarts to the number of backends you may use.

--
[]'s
Hugo
www.devin.com.br



More information about the varnish-misc mailing list