Last active
August 29, 2023 07:49
-
-
Save section-io-gists/8e1c36afe91c4a927e465976c3bf342a to your computer and use it in GitHub Desktop.
Varnish 4 - Custom maintenance page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
commented
Oct 9, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment