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?

2 Answers 2


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.

  • 1
    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
    Commented Dec 6, 2015 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.
    – nuts
    Commented Dec 8, 2015 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;
  • Nope. :( I tried your config changes in both locations but no success. Commented May 27, 2013 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .