Paul B. Henson
May 02, 2019 08:54PM
So, I've got a need for a reverse proxy where first it tries server A;
if it gets a 404 from server A it should try server B, and then just
return whatever happens with server B.

I've got this config so far:

location /_nginx_/ {
internal;
root /var/www/localhost/nginx;
}

location / {

proxy_intercept_errors on;
error_page 403 /_nginx_/error_403.html;
error_page 404 = @server_b;
error_page 405 /_nginx_/error_405.html;
error_page 500 /_nginx_/error_500.html;
error_page 502 /_nginx_/error_503.html;
error_page 503 /_nginx_/error_503.html;
proxy_pass https://serverA;
proxy_redirect http://$host/ /;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_connect_timeout 3m;
proxy_read_timeout 3m;
proxy_buffers 1024 4k;
}

location @server_b {
proxy_intercept_errors off;
proxy_pass https://serverB;
proxy_redirect http://$host/ /;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_connect_timeout 3m;
proxy_read_timeout 3m;
proxy_buffers 1024 4k;
}

This seems to work *except* when it fails to connect to server B, in which
case it gives a standard nginx 502 error page rather than a custom page.

I've tried all kinds of things, from setting proxy_intercept_errors on
for the @server_b location and adding error_page configuration like in
the / location, and a bunch of other stuff I can't even remember exactly,
but no matter what I do I always get the stock nginx 502 rather than
the custom error page.

Ideally I'd like to just pass through whatever error comes from B, unless
nginx fails completely to connect to B, in which case I'd like to pass
the local custom error page rather than the default nginx page.

What am I missing?

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

custom 502 error for stacked proxies

Paul B. Henson May 02, 2019 08:54PM

Re: custom 502 error for stacked proxies

Sergey Kandaurov May 03, 2019 06:48AM

Re: custom 502 error for stacked proxies

Paul B. Henson May 03, 2019 03:50PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 282
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