How to handle 500 Error on upstream itself, While Nginx handle other 5xx errors

Maxim Dounin mdounin at
Mon Jul 10 12:18:14 UTC 2017


On Fri, Jul 07, 2017 at 04:39:47PM +0300, ender ulusoy wrote:

> We have a NGINX reverse proxy (clustered) with 45 upstreams (22 domains, 20
> subdomains, 11 apps).
> Some of our projects hosts apis for some users globally.
> Our developers designed special custom 500 responses for special cases and
> want to show that messages only for tomcat_api upstream.
> They want to serve 500 pages and handle exceptions on tomcat_api upstream
> members not on NGINX. But we want to handle all other 5xx errors on NGINX.
> As I can not succeeded need a hand right now.

Errors interception in the proxy module works as follows:

- Errors are only intercepted if proxy_intercept_errors is set to 
  "on", see  When 
  errors are not intercepted, all errors returned by upstream are sent 
  to the client as is.

- With "proxy_intercept_errors on", nginx will only intercept 
  errors with error_page configured.

That is, if you want to intercept all 5xx errors but not 500, 
consider configuration like this:

    proxy_pass ...
    proxy_intercept_errors on;
    error_page 501 502 503 504 505 /errors/5xx.html;

This will intercept all 5xx errors except 500.

For more information, see the documentation of the directives here:

Maxim Dounin

More information about the nginx mailing list