views:

138

answers:

1

Hi there,

We used to have a caching proxy setup using a very early version of Varnish (0.5ish, I think) which used the 'restart' action to send requests to a second backend in the case of a 404 on the first.

The new version of Varnish doesn't seem to support this - the 'restart' action no longer seems to be supported, and the 'req.restarts' variable is no longer recognised. Is such behaviour possible?

The documentation seems to be out of date, as do many of the online examples. man 7 vcl seems to reflect current behaviour though.

If it's not possible with Varnish, can you suggest another solution?

Here are the relevant bits of our old Varnish config:

sub vcl_recv {

    # remove cookies
    remove req.http.Cookie;

    if (req.restarts == 0) {
        set req.backend = backend1;
    } else if (req.restarts == 1) {
        set req.backend = backend2;
    }

    # remove any query strings
    set req.url = regsub(req.url, "\?.*", "");

    # force lookup even when cookies are present
    if (req.request == "GET" && req.http.cookie) {
        lookup;
    }
}

sub vcl_fetch {
    # we might set a cookie from the Rails app
    remove obj.http.Set-Cookie;

    # force minimum ttl of 1 year
    if (obj.ttl < 31536000s) {
        set obj.ttl = 31536000s;
    }

    if (obj.status != 200 && obj.status != 302) {
        restart;
    }
}
+1  A: 

It seems this behaviour has been reinstated in more recent versions of Varnish.

Andy Triggs