2

I want to use Nginx as a simple reverse proxy, but if the server behind Nginx is down I just was to display a blank page. For some reason this configuration isn't displaying a blank page on error 502 and I can't figure out why.

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    use epoll;
    # multi_accept on;
}

http {

    keepalive_timeout 65;
    proxy_read_timeout 200;

    upstream tornado {
        server 127.0.0.1:8001;
    }

    server {
        listen 80;
        server_name www.something.com;

        location / {
            error_page 502 = @blank;
            proxy_pass http://tornado;
        }

        location @blank {
            index index.html;
            root /web/blank;
        }
    }
}

3 Answers 3

7

I believe that "root" is ignored in named locations (@blank). Can't say if this is by design or a bug.

This works for me (0.7.67):

    location / {
        error_page 502 = /blank.html;
        proxy_pass http://tornado;
    }

    location = /blank.html {
        root /foo/bar;
    }
1

I added the following configuration inside the server directive of a virtual host configuration file. It is working only if you place it there. Nginx will complain and will not reload if you place it inside the nginx.conf. You are free to test and validate it through the command nginx -t.

server {
    // ........

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html/;
    }

    // ........
}

Then, you should add the a file in the location /usr/share/nginx/html/50x.html which will be displayed after a 500/502/503/504 http response status.

echo "If you see me, then you got a 50x response status" | sudo tee /usr/share/nginx/html/50x.html

Tested for nginx/1.14.2

0

Specify "error_page" for whole server, not for "location /"

1
  • That didn't seem to work. Thanks though.
    – user55583
    Sep 29, 2010 at 23:48

You must log in to answer this question.