Welcome! Log In Create A New Profile

Advanced

Re: custom 502 error for stacked proxies

Sergey Kandaurov
May 03, 2019 06:48AM
> On 3 May 2019, at 03:52, Paul B. Henson <henson@acm.org> wrote:
>
> 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.

Hello,

you may want to try recursive error pages in location / {}
with error_page 502 in @server_b.
See for details: http://nginx.org/r/recursive_error_pages

--
Sergey Kandaurov

_______________________________________________
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: 106
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready