503 remove backends response

Thomas Lecomte thomas.lecomte at virtual-expo.com
Tue Jul 22 07:24:29 CEST 2014


On Tue, Jul 22, 2014 at 7:13 AM, Tobias Honacker
<t.honacker at googlemail.com> wrote:
> if ( (obj.status >= 500 || obj.status <= 505) && (req.url ~ "^/appserver/")
> ) {
>       set obj.http.Cache-Control = "public, max-age=10";
>       set obj.status = 200;
>       set obj.response = "OK";
>       return (deliver);
>   }
>
> we are aiming to serve a blank 200 status so that the error disappear on our
> site where the ESI is included.
>
> how could we fix that issue? is there any way not using synthetic while
> serving blank html code? i dont like this "workaround".

Hello,

You can throw a custom error in the VCL, and catch it in vcl_error to
serve blank synthetic content:

 if ( (obj.status >= 500 || obj.status <= 505) && (req.url ~ "^/appserver/") ) {
     error 942 "Backend down";

     return (deliver);
 }

sub vcl_error {
  if (obj.status == 942) {
       set obj.http.Cache-Control = "public, max-age=10";
       set obj.status = 200;
       set obj.response = "OK";
       synthetic "";
       return (deliver);
   }
}

Please note however than when varnish delivers content from vcl_error,
it sends a Connection: close header, which can make things slower
since the client will have to re-establish the connection for further
requests.

-- 
Thomas Lecomte



More information about the varnish-misc mailing list