Skip to content

Instantly share code, notes, and snippets.

@koheyamada
Created December 20, 2018 06:39
Show Gist options
  • Save koheyamada/9b10edd876a7c3dad19dc58b0b67a516 to your computer and use it in GitHub Desktop.
Save koheyamada/9b10edd876a7c3dad19dc58b0b67a516 to your computer and use it in GitHub Desktop.
nginxでメンテナンスページを表示させる。改良版 ref: https://qiita.com/kooohei/items/095eb1304f9fa67ed1a1
error_page 500 @maintenance;
# Set Env
set $maintenance "on";
# Allow Paths
if ($uri ~ "^/exclude/") {
set $maintenance "off";
}
# Allow IPs
if ($remote_addr ~ "xxx.xxx.xxx.xxx") {
set $maintenance "off";
}
if ($http_x_forwarded_for ~ "xxx.xxx.xxx.xxx") {
set $maintenance "off";
}
# maintenance
if ($maintenance = "on") {
return 500;
}
location @maintenance {
rewrite ^(.*)$ /maintenance.html break;
}
# include /etc/nginx/conf.d/maintenance;
rewrite ^/maintenance.html(.*)$ https://$host/ permanent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment