Skip to content

Instantly share code, notes, and snippets.

@bcambel
Created August 16, 2013 06:57
Show Gist options
  • Save bcambel/6247835 to your computer and use it in GitHub Desktop.
Save bcambel/6247835 to your computer and use it in GitHub Desktop.
Nginx maintenance redirect when a specific file exists
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;
}
}
Copy link

ghost commented Jun 14, 2018

Why using rewrite where you could use try_files /maintenance.html =404; ?

Source: https://www.nginx.com/blog/creating-nginx-rewrite-rules/

@rpkamp
Copy link

rpkamp commented Jul 4, 2018

@fboutin-pmc because try_files will serve the file with HTTP status code 200, and that's not nice for search engines and the likes.

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