Created
September 11, 2015 10:26
-
-
Save rictorres/5d3c7314f2756448c1a3 to your computer and use it in GitHub Desktop.
nginx maintenance mode
This file contains 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
server { | |
listen 80; | |
server_name mysite.com; | |
root /var/www/mysite.com/; | |
location / { | |
if (-f $document_root/maintenance.html) { | |
return 503; | |
} | |
... # the rest of your config goes here | |
} | |
error_page 503 @maintenance; | |
location @maintenance { | |
rewrite ^(.*)$ /maintenance.html break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now whenever you need to take your site offline, simply create the file
maintenance.html
in the$document_root
(in our case,/var/www/mysite.com
). If the file exists, Nginx will serve it with a 503 status code, if not, it will proceed as usual.https://lincolnloop.com/blog/pro-tip-redirecting-custom-nginx-maintenance-page/