Michael
Michael

Reputation: 178

Varnish vcl_error should exclude static files for maintenance

When you need a maintenance site in your Varnish, the default way is to serve it via sub vcl_error() by calling error 503.

The problem here is, when you need js/css/images in your maintenance site and they are hosted on the same URL, as all of this files will end up in a 503 too.

Is there a way to exclude specific files or files by file extension? I tried several ways, e.g. placing an if() statement around the error 503 and just enter it if file extension is not png,jpg,js,css. But it leads to a timeout.

Most time i've been reading, that placing files on e.g. Cloudflare or use base64 encoding for images and inline css/js if needed.

Are these the only ways?

Upvotes: 0

Views: 389

Answers (2)

Rastislav Kassak
Rastislav Kassak

Reputation: 148

They are right, base64 encoded images and inline css, js, etc... is safest bet.

  • whole response is single atomic payload
  • you don't need to clutter your vcl with such corner cases
  • no way to directly visits assets by crawlers
  • no risk of cache propagation of maintenance assets to sites out of control (forward proxies)

and on and on.

BTW, you don't have to put html file inside vcl, you could use this statement:

synthetic std.fileread("/etc/varnish/error.html");

and all you need is single inline html from design department.

Upvotes: 1

Michael
Michael

Reputation: 178

Ok, i've found a workaround that works for me now.

In the HTML code, that represents the maintenance site, i've used URLs including the backend port. So the requests won't hit the Varnish itself but the Apache server.

Upvotes: 0

Related Questions