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.

Im trying to catch a 502 bad gataway for nginx with unicorn. This error is thrown when unicorn is not running. Im trying to use a custom error page instead for when unicorn is not running to no avail.

What did I miss? according to docs this should be right and I just don't see any errors.

upstream unicorn { server unix:/srv/host/shared/tmp/unicorn.sock fail_timeout=0; }

server {

    listen 80 deferred;
    server_name host.com host.com
    client_max_body_size 4G;
    keepalive_timeout 10;

    root /srv/host/public;

    location / {
        try_files /system/maintenance.html $uri/index.html $uri @unicorn;
    }

    try_files $uri/index.html $uri @unicorn;

    location @unicorn {
        error_page 502 /system/maintenance.html;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://unicorn;
    }

}

My nginx error.log shows:

 unix:/srv/host/shared/tmp/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 83.117.60.95, server: host.com, request: "GET / HTTP/1.1", upstream: "http://unix:/srv/host/shared/tmp/unicorn.sock:/", host: "host.com"
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Yes, you can have custom error-pages in nginx. Add something like the following to your config:

error_page  502 /path/to/error-pages/502_bad_gateway.html;
share|improve this answer
    
Hi Nick, ive updated the orginal question to be more clear, its strange but as above it won't work. Could you confirm there are no errors in this config? it won't get the 502 nor display any errors of the maintenance.html file not found so the 502 rule seems not triggered –  Rubytastic Sep 13 '12 at 17:56
    
error_page should be in your server block, not the location block. –  Michael Hampton Sep 13 '12 at 17:59

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.