502 from upstream not handled by nginx error_page

Hi,

I’m having issues serving up a custom 502 using upstream; essentially
nginx’s 502 is always shown, despite having a custom 502 page set up
with error_page.

The configuration is here:
http://pastie.org/private/8kjglkprvw8pfoeqkjcbug

I’ve tried this with proxy_intercept_errors on, off, in the location and
server blocks. Sadly, no dice.

Error logs show nothing but 2009/06/12 20:04:43 14569#0: *2 no live
upstreams while connecting to upstream

The file it’s trying to serve from for the 502 page is in the same
folder with the same permissions as the static data nginx hosts anyway.

Any ideas why this 502 is being ignored?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2871,2871#msg-2871

On Fri, Jun 12, 2009 at 04:15:24PM -0400, JamesHarrison wrote:

The file it’s trying to serve from for the 502 page is in the same folder with the same permissions as the static data nginx hosts anyway.

Any ideas why this 502 is being ignored?

You should use location, but not path in error_page:

error_page 502 /opt/www/charactr/current/public/502.html;

error_page 502 /502.html;

loction = /503.html {
# the root is iherited from server level
#root /opt/www/charactr/current/public/;
}

Instead of

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;

if (-f $request_filename/index.html) {
  rewrite (.*) $1/index.html break;
}

if (-f $request_filename.html) {
  rewrite (.*) $1.html break;
}

if (!-f $request_filename) {
  proxy_pass http://charactrapp;
  break;
}

}

it’s better to use

location / {
try_files $uri/index.html $uri.html $uri @charactrapp;
}

location @charactrapp {
proxy_pass http://charactrapp;

proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;

}

Also, if you use 0.7.x, it’s better to use

gzip_disable msie6;

instead of

gzip_disable “MSIE [1-6].”;

Fantastic, and thanks for the extra tips. Working perfectly.

Cheers!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2871,2874#msg-2874