Skip to content

Instantly share code, notes, and snippets.

@halfd
Created September 23, 2013 13:39
Show Gist options
  • Save halfd/6670541 to your computer and use it in GitHub Desktop.
Save halfd/6670541 to your computer and use it in GitHub Desktop.
Maintenance mode in NGINX - the quick hack. Turn on/off by placing HTML file in relevant folder
# Variable used for multiple IF hack
set $is_maintenance "";
# Check for notice HTML file
if (-f /var/www/django/kontrafon/templates/maintenance.html) {
set $is_maintenance M;
}
# Use this to circumvent maintenance message
if ($remote_addr != "1.2.3.4") {
set $is_maintenance "${is_maintenance}IP";
}
# Only if file is there and remote addr is not us
if ($is_maintenance = MIP) {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
root /path/to/templates/;
rewrite ^(.*)$ /maintenance.html break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment