Varnish - set backend if statuscode is 404
Tobias Honacker
t.honacker at googlemail.com
Thu Nov 28 16:30:14 CET 2013
Hi Jan,
This is my solution:
sub vcl_recv {
// Redirect 404er Pictures - vcl_fetch will restart request and set new
header to match with this rule
if (req.http.host == "new-header.de") {
if (req.url ~ "^/var/storage/images") {
set req.backend = new_backend;
}
}
}
sub vcl_fetch {
if ((beresp.status == 404) && (req.url ~ "^/var/storage/images")) {
set req.http.Host = "new-header.de";
return(restart);
}
}
You have to set a new header and restart the request thats it.
Best regards,
Tobias
Am 28.11.13 16:15 schrieb "Jan-Frode Myklebust" unter <janfrode at tanso.net>:
>If you manage to do this, I would much appreciate you post a recipie :-)
>I've been struggeling trying to achieve the same thing, without
>success..
>
>Actually my setup is a bit different, we have a director, and just want
>to check the other backend if the first backend gives 404, but the same
>solution might apply.
>
>backend backend1 {
> .host = "backend1.example.com";
> .probe = {
> .url = "/alive.html";
> .timeout = 34 ms;
> .interval = 2s;
> .window = 10;
> .threshold = 8;
> }
>}
>backend backend2 {
> .host = "backend2.example.com";
> .probe = {
> .url = "/alive.html";
> .timeout = 34 ms;
> .interval = 2s;
> .window = 10;
> .threshold = 8;
> }
>}
>director dir1 client {
> { .backend = backend1; .weight = 1; }
> { .backend = backend2; .weight = 1; }
>}
>sub vcl_recv {
> if ( req.http.host ~ "(?i)www.example.com$" ) {
> set req.backend = dir1;
> return(lookup);
> }
>}
>
>
>
> -jf
More information about the varnish-misc
mailing list