I have nginx set up to serve uWSGI for a Flask app. Sometimes there will be errors or I will be restarting the uWSGI service, but I want nginx to serve a nicer maintenance page instead of the default 502 Bad Gateway that happens when uWSGI doesn't respond. I have tried multiple configs that are supposed to do this but none of them seem to have any effect. Here is my current config:
server {
listen 80;
server_name mydomain.com;
charset utf-8;
client_max_body_size 75M;
location / {
try_files $uri @flask;
error_page 502 =200 @maintenance;
}
location @flask {
include uwsgi_params;
uwsgi_pass unix:/path/to/socket/uwsgi.sock;
}
location @maintenance {
root /path/to/web;
rewrite ^(.*)$ /maintenance.html break;
}
}
error_page
directive should be in@flask
location. Probably you'll also needuwsgi_intercept_errors on;
there.