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

ender ulusoy enderulusoy at
Fri Jul 7 13:39:47 UTC 2017

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.

Here is the server configuration follows, could you please help?

Thank you.

server {

  location / {
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header x-redirect-uri hotcoldwarm;
    add_header Strict-Transport-Security "max-age=31536000;
includeSubdomains; always";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://tomcat_api;
    proxy_next_upstream error timeout http_502 http_503 http_504 http_404;
    proxy_connect_timeout   1;
    listen 80;
    listen 443 ssl;
    ssl_certificate /etc/rapidssl/live/;
    ssl_certificate_key /etc/rapidssl/live/;
    include /etc/rapidssl/options-ssl-nginx.conf;
    if ($scheme != "https") {
        return 301 https://$host$request_uri;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list