Varnish error for failed backend

Geoff Simmons geoff at uplex.de
Sat Mar 31 11:25:31 UTC 2018


On 03/31/2018 10:21 AM, Danila Vershinin wrote:
> 
> If a constant PHP error occurs in the backend and there is no cache -
> we see Backend fetch failed.
[...]

> ... it always takes time to explain to the clients that the Varnish
> is not to blame ...
Welcome to Varnish administration! Such is the life.

When the backend fetch fails, always look to the FetchError entry in the
backend log, which diagnoses the problem. It helps with those conversations.

> ... and ideally there would be a way to deliver different Varnish
> error page for these 3 cases:>
> * 500 error-ed backend
> * 404-ed backend
> * actual problem talking to the backend (HTTP etc.)

Varnish can generate the response itself with vcl_synth -- when you see
the Guru Meditation and "Backend fetch failed", you're seeing the
buitlin.vcl version of vcl_synth.

vcl_synth is called automatically for response codes 500 & 503, for 404
or anything else, your VCL has to direct to there:

sub vcl_deliver {
	if (resp.status == 404) {
		return (synth(404));
	}
}

So you could have something like this:

sub vcl_synth {
	if (resp.status == 500) {
		synthetic("500 error-ed backend");
	}
	elsif (resp.status == 404) {
		synthetic("404-ed backend");
	}
	elsif (resp.reason == "Backend fetch failed") {
		synthetic("actual problem talking to the backend");
	}
}

Since I believe about Varnish 5.0 or so you can use also this syntax to
generate the synthetic response (synthetic() works as well):

	set resp.body = "mumble";

Of course you'll probably want to have HTML markup in the generated
response -- look to the Guru Meditation in builtin.vcl's vcl_synth for
an example.


HTH,
Geoff
-- 
** * * UPLEX - Nils Goroll Systemoptimierung

Scheffelstraße 32
22301 Hamburg

Tel +49 40 2880 5731
Mob +49 176 636 90917
Fax +49 40 42949753

http://uplex.de

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20180331/3f960291/attachment.bin>


More information about the varnish-misc mailing list