Nginx error_page for 502 Bad Gateway errors

nginx

Here is my server 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;
            }
    }

When the upstream app is not online, I am getting the default nginx 502 page for the root path (that is: GET /). Any idea why this is happening? I'd like the root path to respond with the maintenance page just like any other request path.

Best Answer

I did this for the whole vhost:

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

This works perfectly for me.