Created
September 23, 2013 13:39
-
-
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
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
# 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