# partially based on https://onehub.com/blog/2009/03/06/rails-maintenance-pages-done-right/ recursive_error_pages on; set $maintenance off; set $maintenance_bypass off; # https://blog.ed.gs/2013/01/25/nginx-multiple-if-statements/ set $maintenance_test maint_off; set $bypass_test bypass_on; set $ip_test ip_unmatched; set $all_tests no; if (-f $document_root/maintenance/maintenance.on) { set $maintenance_test maint_on; set $maintenance on; } if (-f $document_root/maintenance/maintenance_bypass.off) { set $bypass_test bypass_off; } if ($remote_addr ~ <%= Pvcglue.cloud.dev_ip_addresses.join('|').gsub('.', '\.') %>) { set $ip_test ip_match; } set $all_tests "${maintenance_test}__${bypass_test}__${ip_test}"; if ($all_tests = maint_on__bypass_on__ip_match) { set $maintenance off; set $maintenance_bypass on; # only add header when maintenance is on and the remote address is a dev ip address and bypass is on } if ($uri ~ ^/maintenance/.*) { set $maintenance off; } if ($maintenance = on) { return 503; # 503 - Service unavailable } location /maintenance { } #error_page 404 /404.html; #error_page 500 502 504 /500.html; error_page 503 @503; location @503 { error_page 405 = /maintenance/maintenance.html; # Serve static assets if found. rewrite ^(.*)$ /maintenance/maintenance.html break; }