It is quite possible in varnish. Make sure that in vcl_fetch (and possibly in vcl_error) you check the return status code (for example, check stats> 400), restart if it fails, and in vcl_recv select a different backend if req.restarts> 0. For example :
backend serverA {
.host="192.168.0.1";
.port = "80";
}
backend serverB {
.host = "192.168.0.2";
.port = "80";
}
sub vcl_recv {
if (req.restarts == 0) {
set req.backend = serverB;
} else {
set req.backend = serverA;
}
}
sub vcl_fetch {
if (obj.status >= 400 && req.restarts == 0) {
restart;
}
}
sub vcl_error {
if (req.restarts == 0) {
restart;
}
}
, , , -. Varnish - -. (serverA) ? , (), !:)