Skip to content

Instantly share code, notes, and snippets.

@section-io-gists
Last active August 29, 2023 07:49
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save section-io-gists/8e1c36afe91c4a927e465976c3bf342a to your computer and use it in GitHub Desktop.
Save section-io-gists/8e1c36afe91c4a927e465976c3bf342a to your computer and use it in GitHub Desktop.
Varnish 4 - Custom maintenance page
import std;
acl whitelist {
"123.123.123.123";
"216.3.128.12";
}
sub vcl_recv {
# If not a whitelisted IP, then display maintenance page. Requires std library.
if(std.ip(regsub(req.http.X-Forwarded-For, "[, ].*$", ""), client.ip) !~ whitelist) {
return (synth(800, "Maintenance page"));
}
}
sub vcl_synth {
if (resp.status == 800) {
set resp.http.Content-Type = "text/html; charset=utf-8";
set resp.status = 503;
set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0";
synthetic( {"
<html><head></head>
<body>
Sorry this website is currently under going maintenance, please try again soon.
</body></html>
"} );
return (deliver);
}
}
@hatemzidi
Copy link

# prepare the maintenance mode 
$ varnishadm vcl.load maintenance_mode /etc/varnish/CustomMaintenancePage.vcl

# maintenance on 
$ varnishadm vcl.use maintenance_mode

# maintenance off
$ varnishadm vcl.use boot # boot is the default mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment