Redirect 503 errors with req.restarts and vcl_error

Fredrik Nygren fredrik.nygren at gotamedia.se
Tue Mar 3 21:46:21 CET 2009


Hi,
I have a backend server (with Tomcat). It happens that my backend  
server responds with a 503 message when is not available. In these  
cases, I want to redirect my visitors to another backend server that  
has a static HTML error page. But for some reason, my visitors sees  
Varnish default 503 message (Guru Meditation blabla ...) instead  
geting a redirect to the static backend. Advice please?

I use Varnish varnish-2.0.3-1.

Here is my VCL file:

backend barren {
	.host = "10.0.0.1";
	.port = "8090";
}

sub vcl_recv{
	if(req.http.host ~ "varnish\.domain\.se$"){
    		if(req.restarts == 0){
    			set req.http.host = "varnish.domain.se";
    			set req.backend = barren;
    		}else{
    			error 750 "domain.se";	
    		}
	}
}

sub vcl_error{
	if(obj.status == 750){
        	if(obj.response ~ "domain\.se"){
            		set obj.http.Location = "http://www2.domain.se/whooops/index.html 
";
		}
		set obj.status = 302;
        	deliver;
	}
}

sub vcl_fetch {
	if(obj.status != 200){
		restart;
	}
}

Regards
<fredrik />








More information about the varnish-misc mailing list