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 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 / {
            proxy_pass      http://192.168.1.78/;
            include         /etc/nginx/proxy.conf;
    }
share|improve this question
    
You already do. What is the problem? –  Michael Hampton Sep 11 '12 at 14:01
    
I receive a 502 "Bad gateway" instead that error.html –  Lormayna Sep 11 '12 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: 192.168.1.112, server: hansolo, request: "GET /error.html HTTP/1.1", upstream: "192.168.1.78:80/error.html";, host: "192.168.1.68" –  Lormayna Sep 11 '12 at 14:31
add comment

1 Answer

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 {
    internal;
}

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.

share|improve this answer
add comment

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.