Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have an nginx web server sitting in front of a Jetty Java app server running a web application.

I'd like to configure nginx to return a HTTP 503 if the proxied Jetty server is down.

This way when I bring the app server down for maintenance, of if it happens to crash, a 503 is returned to any clients letting them know the site is temporarily unavailable.

However, with the basic configuration, Nginx returns a HTTP 502 Bad Gateway when it can't connect to the proxy_pass location.

Is it possible to configure nginx to report a 503 instead?

share|improve this question
up vote 3 down vote accepted

You can do so by setting an error page.

error_page 502 =503 /maintenance.html
share|improve this answer

With just the contents of Martin Fjordvald's answer I was still getting 502, I didn't have a real maintenance.html page, but this seems to work:

    location / {
        error_page 502 =503 /maintenance.html;
        include proxy_params;
        proxy_pass http://unix:/var/run/my.sock;
    }
    location /maintenance.html {
        return 503;
    }
share|improve this answer

Your Answer

 
discard

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.