From 76fc6ecb47d93b6cfcc12b3286c134fabc4bd5d5 Mon Sep 17 00:00:00 2001 From: Chris MacLeod Date: Thu, 30 Apr 2020 10:51:48 -0400 Subject: [PATCH] Changes to nginx @maintenance handler previous configuration would not display maintenance page if omero.web wasn't running. This was likely due to the request being passed to the @proxy_to_app named location and the configuration not being inherited into that stanza. This commit moves the error_page directive up to the server container where possible or duplicates the directive into the named location directive otherwise. Additionally the return code is set to 502 to avoid situations where returning the maintenance page causes a 200 return code and confusing monitoring systems. (502 is always 502 with the current configuration. --- omeroweb/templates/nginx-development.conf.template | 2 +- omeroweb/templates/nginx-location.conf.template | 3 ++- omeroweb/templates/nginx.conf.template | 2 +- .../reference_templates/nginx-development-withoptions.conf | 2 +- test/unit/reference_templates/nginx-development.conf | 2 +- test/unit/reference_templates/nginx-location-withoptions.conf | 3 ++- test/unit/reference_templates/nginx-location.conf | 3 ++- test/unit/reference_templates/nginx-withoptions.conf | 2 +- test/unit/reference_templates/nginx.conf | 2 +- 9 files changed, 12 insertions(+), 9 deletions(-) diff --git a/omeroweb/templates/nginx-development.conf.template b/omeroweb/templates/nginx-development.conf.template index 75dafb63a0..504c414426 100644 --- a/omeroweb/templates/nginx-development.conf.template +++ b/omeroweb/templates/nginx-development.conf.template @@ -33,6 +33,7 @@ http { sendfile on; client_max_body_size %(MAX_BODY_SIZE)s; + error_page 502 =502 @maintenance%(PREFIX_NAME)s; %(NGINX_SERVER_EXTRA_CONFIG)s @@ -59,7 +60,6 @@ http { location %(FORCE_SCRIPT_NAME)s { - error_page 502 @maintenance%(PREFIX_NAME)s; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app%(PREFIX_NAME)s; } diff --git a/omeroweb/templates/nginx-location.conf.template b/omeroweb/templates/nginx-location.conf.template index 8a2018dfbe..bda38ef2fe 100644 --- a/omeroweb/templates/nginx-location.conf.template +++ b/omeroweb/templates/nginx-location.conf.template @@ -26,6 +26,7 @@ location %(STATIC_URL)s { } location @proxy_to_app%(PREFIX_NAME)s { + error_page 502 =502 @maintenance%(PREFIX_NAME)s; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; @@ -37,7 +38,7 @@ location @proxy_to_app%(PREFIX_NAME)s { location %(FORCE_SCRIPT_NAME)s { - error_page 502 @maintenance%(PREFIX_NAME)s; + error_page 502 =502 @maintenance%(PREFIX_NAME)s; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app%(PREFIX_NAME)s; } diff --git a/omeroweb/templates/nginx.conf.template b/omeroweb/templates/nginx.conf.template index b9350515d4..7ff31cd58a 100644 --- a/omeroweb/templates/nginx.conf.template +++ b/omeroweb/templates/nginx.conf.template @@ -8,6 +8,7 @@ server { sendfile on; client_max_body_size %(MAX_BODY_SIZE)s; + error_page 502 =502 @maintenance%(PREFIX_NAME)s; %(NGINX_SERVER_EXTRA_CONFIG)s @@ -34,7 +35,6 @@ server { location %(FORCE_SCRIPT_NAME)s { - error_page 502 @maintenance%(PREFIX_NAME)s; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app%(PREFIX_NAME)s; } diff --git a/test/unit/reference_templates/nginx-development-withoptions.conf b/test/unit/reference_templates/nginx-development-withoptions.conf index de1293a700..8ee1f5198f 100644 --- a/test/unit/reference_templates/nginx-development-withoptions.conf +++ b/test/unit/reference_templates/nginx-development-withoptions.conf @@ -33,6 +33,7 @@ http { sendfile on; client_max_body_size 2m; + error_page 502 =502 @maintenance_test; # <<<<< omero.web.nginx_server_extra_config listen 443 ssl; @@ -63,7 +64,6 @@ ssl_certificate_key /dummy/private.key; location /test { - error_page 502 @maintenance_test; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app_test; } diff --git a/test/unit/reference_templates/nginx-development.conf b/test/unit/reference_templates/nginx-development.conf index e7599da4f1..af0590e8d7 100644 --- a/test/unit/reference_templates/nginx-development.conf +++ b/test/unit/reference_templates/nginx-development.conf @@ -33,6 +33,7 @@ http { sendfile on; client_max_body_size 0; + error_page 502 =502 @maintenance; @@ -59,7 +60,6 @@ http { location / { - error_page 502 @maintenance; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app; } diff --git a/test/unit/reference_templates/nginx-location-withoptions.conf b/test/unit/reference_templates/nginx-location-withoptions.conf index 7b6907e101..cd668746f2 100644 --- a/test/unit/reference_templates/nginx-location-withoptions.conf +++ b/test/unit/reference_templates/nginx-location-withoptions.conf @@ -26,6 +26,7 @@ location /test-static { } location @proxy_to_app_test { + error_page 502 =502 @maintenance_test; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; @@ -37,7 +38,7 @@ location @proxy_to_app_test { location /test { - error_page 502 @maintenance_test; + error_page 502 =502 @maintenance_test; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app_test; } diff --git a/test/unit/reference_templates/nginx-location.conf b/test/unit/reference_templates/nginx-location.conf index ed47f43598..c6be915b19 100644 --- a/test/unit/reference_templates/nginx-location.conf +++ b/test/unit/reference_templates/nginx-location.conf @@ -26,6 +26,7 @@ location /static { } location @proxy_to_app { + error_page 502 =502 @maintenance; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; @@ -37,7 +38,7 @@ location @proxy_to_app { location / { - error_page 502 @maintenance; + error_page 502 =502 @maintenance; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app; } diff --git a/test/unit/reference_templates/nginx-withoptions.conf b/test/unit/reference_templates/nginx-withoptions.conf index 0d208dd8dd..3b14f59272 100644 --- a/test/unit/reference_templates/nginx-withoptions.conf +++ b/test/unit/reference_templates/nginx-withoptions.conf @@ -8,6 +8,7 @@ server { sendfile on; client_max_body_size 2m; + error_page 502 =502 @maintenance_test; # <<<<< omero.web.nginx_server_extra_config listen 443 ssl; @@ -38,7 +39,6 @@ ssl_certificate_key /dummy/private.key; location /test { - error_page 502 @maintenance_test; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app_test; } diff --git a/test/unit/reference_templates/nginx.conf b/test/unit/reference_templates/nginx.conf index e41ec5e43f..86c74e6d51 100644 --- a/test/unit/reference_templates/nginx.conf +++ b/test/unit/reference_templates/nginx.conf @@ -8,6 +8,7 @@ server { sendfile on; client_max_body_size 0; + error_page 502 =502 @maintenance; @@ -34,7 +35,6 @@ server { location / { - error_page 502 @maintenance; # checks for static file, if not found proxy to app try_files $uri @proxy_to_app; }