I have Nginx working as reverse proxy and Django application behind it. Django app is connected to Nginx through UWSGI. Django app is deployed using Docker and gets down for a second or so during deployment. I would like to instruct Nginx to return custom 503 error page during that period.
Below is my Nginx config:
upstream server_django {
server 0.0.0.0:8000;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name server.com;
location / {
# required to serve static assets
alias /data/server.com/website_root/;
try_files $uri @django;
}
location @django {
uwsgi_pass server_django;
include /etc/nginx/uwsgi_params;
}
}
I have tried adding following config inside "server" block:
uwsgi_intercept_errors on; error_page 502 503 504 =503 @django_is_down; location @django_is_down { root /error_pages/server.com/; add_header Retry-After 10 always; index 503.html; }
but it didn't help since Nginx stared serving default 404 page when backend is down.
How do I detect when Django is down in Nginx and serve custom error page when that happens?