Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing status code from 502 to 503 in fallback route

Tags:

nginx

I'm using nginx as proxy server for my project. In case my app is offline for maintenance I'd like to show a fallback page. This works fine so far. The only problem is, that the server response with a 502 error code - which makes sense. How do I change it to a 503 route in my fallback though?

server {
    listen 80;
    error_page 500 502 503 504 @fallback;

   location / {
     proxy_pass http://0.0.0.0:3000;
   }

   location @fallback {
       // I need this to answer with a status of 503 instead of a 502
       root /srv/my-project/static;
       try_files /fallback.html;
   }

}
like image 821
Seltsam Avatar asked Jan 17 '26 05:01

Seltsam


1 Answers

you can set a error page nginx error page

and set somethig like

error_page 502 =503 /maintenance.html

or something like

    location / {
        error_page 502 =503 /maintenance.html;
        include proxy_params;
        proxy_pass http://unix:/var/run/my.sock;
    }
    location /maintenance.html {
        return 503;
    }

source : How can I make Nginx return HTTP 503 when my proxied app server is down?

like image 163
shalbafzadeh Avatar answered Jan 19 '26 19:01

shalbafzadeh