Welcome! Log In Create A New Profile

Advanced

Using error_page to a named location - possible?

Ed W
March 06, 2012 11:38AM
Hi, as part of a larger problem I have a captive portal which grabs all
incoming URLs and after evaluating a bunch of logic redirects the caller
somewhere else. I use proxy_pass to pass the request to my cgi code.

However, I would like to customise the error message in the event that
the upstream daemon is unavailable. I can't figure out how to do that
affecting part of the incoming URLs. Is it possible to do something
like "error_page @502_error" in conjunction with proxy_pass?

So, I have

server {
listen 8000 default_server;

root /var/www/cp/htdocs/public;

location / {
proxy_read_timeout 5;
proxy_pass http://127.0.0.1:3000;
error_page 502 /502.html;
proxy_set_header Host $http_host;
proxy_set_header X-Server-Addr $server_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-HTTPS 0;
proxy_set_header X-Captive-Portal-Redirect 1;
}
location /502.html {
internal;
}
}


However, if I visit "http://somewhere/502.html" I get a 404 response
(presumably matching the location /502.html and the 404 is due to the
"internal"?)

I can't see that it's possible to use something like:

location / {
proxy_pass http://127.0.0.1:3000;
error_page 502 @502;
}

location @502 {
index /502.html;
root /var/www;
internal;
}


Does someone have a suggestion on how to customise the error response
without affecting ANY incoming URLs (they must ALL be passed through the
proxy under normal working situation)

(Its occured to me that I could perhaps setup another "server { }" block
listening on another port, then use a different proxy_pass in the
"location @502 {}"? Seems ugly, but would that work?)


Thanks for any thoughts

Ed W

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Using error_page to a named location - possible?

Ed W March 06, 2012 11:38AM

Re: Using error_page to a named location - possible?

Edho Arief March 06, 2012 11:42AM

Re: Using error_page to a named location - possible?

Maxim Dounin March 06, 2012 12:48PM

Re[2]: Using error_page to a named location - possible?

Max March 06, 2012 01:06PM

Re: Using error_page to a named location - possible?

Maxim Dounin March 06, 2012 01:26PM

Re[2]: Using error_page to a named location - possible?

Max March 06, 2012 01:40PM

Re: Using error_page to a named location - possible?

Ed W March 06, 2012 05:34PM

Re: Using error_page to a named location - possible?

Maxim Dounin March 06, 2012 06:30PM

Re: Using error_page to a named location - possible?

Ed W March 07, 2012 04:56AM

Re: Using error_page to a named location - possible?

Edho Arief March 07, 2012 06:40AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 286
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready