Score:0

Make Nginx return custom error page when backend is down

in flag

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?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.