对于502错误的网关错误,nginx error_page

这是我的服务器configuration:

server { listen 0.0.0.0; server_name dev.host.com; location / { include /etc/nginx/proxy.conf; proxy_pass http://127.0.0.1:5000; proxy_redirect default; error_page 502 =200 @maintenance; } location ^~ /(img|js|css)/ { root /path/to/application/assets; expires max; break; error_page 404 =302 /; } location @maintenance { root /path/to/static/offline/files; try_files $uri $uri/ /index.html =503; } } 

当上游应用程序不在线时,我得到根path的默认nginx 502页面(即: GET / )。 任何想法为什么发生这种情况? 我希望根path与维护页面一样响应,就像任何其他请求path一样。

我为整个鬼做了这个:

 server { (...) error_page 500 502 503 504 /5xx.html; location /5xx.html{ root /www/error_pages/; } } 

这对我来说是完美的。

细节中的魔鬼; 我的@maintenance命名的位置没有正确设置。 具体来说,发送参数( $uri/ )到try_files导致了问题。 这是正确的命名的位置:

 location @maintenance { root /path/to/static/offline/files; try_files $uri /index.html =503; }