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

I'm forwarding requests to a local service through a Nginx server. What I try now to accomplish is to fallback to a local error page in case the service becomes unavailable.

My current configuration is

server {
    listen       80;
    server_name  "";

    location / {
        proxy_set_header    Host $host;
        proxy_set_header    X-Real-IP   $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout 1;
        proxy_next_upstream error timeout http_500 http_502 http_503 http_504 http_404;
        proxy_intercept_errors on;

    error_page 501 502 503 @maintenance;
    location @maintenance {
            root   /locust/www/fallback/htdocs;
            index  index.html index.htm;

Proxying works, but as soon as I make my service on 9080 unavailable the index.html of my maintenance location is NOT displayed.

Any suggestions on what is wrong with this config?

share|improve this question
up vote 5 down vote accepted

Actually, I only had to slightly modify your config:

error_page 501 502 503 /500.html;
location = /500.html {
        root   /locust/www/fallback/htdocs;

and obviously rename the index.html you want to present to 500.html.

share|improve this answer
Using this approach, what happens when the application running on the proxy_pass throws a 501, 502, or 503? Some applications (like Django) handle their own 50x errors so they can have custom error pages. Will the approach here trump the application generated 50x error pages with the Nginx 500.html page? – Joe J Dec 6 '15 at 20:28
I haven't tested it, but I'm 99% certain, that exactly those errors will display the /500.html . The idea is, that when nginx is getting 501 502 503 from the proxied server, it will display /500.html. The proxied server being django. – nutz Dec 8 '15 at 14:01

Try to specify exact url for the error page like:

    proxy_intercept_errors on;
    error_page  500 502 503 504 402 403 401  /500.html;
    root   /locust/www/fallback/htdocs;
share|improve this answer
Nope. :( I tried your config changes in both locations but no success. – Sotapanna May 27 '13 at 12:07

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.