Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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_pass  http://127.0.0.1:9080;
        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

2 Answers 2

up vote 2 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

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

 
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.