Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is my server configuration:

    server {

            location / {
                    include /etc/nginx/proxy.conf;
                    proxy_redirect default;

                    error_page 502 =200 @maintenance;

            location ^~ /(img|js|css)/ {
                    root /path/to/application/assets;
                    expires max;

                    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.

share|improve this question

Try setting proxy_intercept_errors on;

share|improve this answer
No luck; tried the directive at the http, server and proxy location blocks – mikeycgto Feb 17 '12 at 17:00

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.

share|improve this answer
This does catch the root path but it's like the try_files directive no longer works. Every request just results in the index.html page so requests for images and CSS fail. – mikeycgto Feb 24 '12 at 20:18
up vote 1 down vote accepted

The devils in the details; my @maintenance named location was not setup correctly. Specifically, the send argument ($uri/) to try_files was causing the problem. Here is the correct named location:

location @maintenance { 
    root /path/to/static/offline/files;
    try_files $uri /index.html =503;
share|improve this answer
Hah, I also followed the blog post at… and ran into the same issue ;D – Oliver Salzburg Feb 1 '15 at 22:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.