I'm using nginx as reverse proxy for a single machine. I would like to have an error page when the backend machine goes down.

This is my configuration file:

server {
    listen   80;
    access_log  /var/log/nginx/access.log;
    root /var/www/nginx;
    error_page 403 404 500 502 503 504 /error.html;
    location / {
            include         /etc/nginx/proxy.conf;
  • You already do. What is the problem? Commented Sep 11, 2012 at 14:01
  • 1
    I receive a 502 "Bad gateway" instead that error.html
    – Lormayna
    Commented Sep 11, 2012 at 14:17
  • This is an error: 2012/09/11 16:32:10 [error] 5544#0: *7 connect() failed (110: Connection timed out) while connecting to upstream, client:, server: hansolo, request: "GET /error.html HTTP/1.1", upstream: "", host: ""
    – Lormayna
    Commented Sep 11, 2012 at 14:31

1 Answer 1


Aha, I see the problem. You have provided no way for nginx to actually serve static files such as /error.html, so it is trying to pass them upstream to your backend.

The quick fix would be:

location /error.html {

This will cause nginx to handle /error.html itself. It will then try to serve the file out of the defined document root.

By the way, you probably want to use different error pages for 4xx errors and 5xx errors. "Not found" or whatever is not what you want people (or search engines!) to see if a backend is down temporarily.

  • You can template the /error.html file, and have it look differently depending on the error code.
    – Qsiris
    Commented Feb 15, 2019 at 13:55
  • Better to have different error_pages for each error, though I suspect something like that is what you had in mind. Commented Feb 15, 2019 at 15:50
  • This is what I had in mind (not my blog): blog.adriaan.io/one-nginx-error-page-to-rule-them-all.html
    – Qsiris
    Commented Feb 17, 2019 at 19:55

You must log in to answer this question.

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