I've configured an varnish instance to deliver a custom maintainance page when it can't reach a backend server instead of the default guru meditation page. The subroutine that delivers the maintainance page looks similar to this:
sub deliver_maintainance_page
{
set obj.http.Content-Type = "text/html; charset=utf-8";
synthetic {"
<!DOCTYPE html>
<html dir="ltr">
...
</html>
"};
return(deliver);
}
The missing html (the dots) also includes image and font resources embedded using the data uri scheme (http://en.wikipedia.org/wiki/Data_URI_scheme). The total weight of the document is ~208 kb.
Is this really the best way to deliver a custom maintainance page ?
I do two things for my custom maintenance pages. I use a CDN or image host (see Amazon S3, CloudFlare, Akamai, Imgur, etc) to host all images on the page (for big sites I recommend a CDN, CloudFlare has a free plan). Then I move the HTML for the page into an external file and use std.fileread
which is built into Varnish. E.g:
import std;
sub deliver_maintainance_page
{
set obj.http.Content-Type = "text/html; charset=utf-8";
synthetic std.fileread("/var/www/errors/503.html");
return(deliver);
}
This cleans up your VCL file and reduces page weight (no more inline images).