1

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;
    }

}
RipperDoc
  • 113
  • 2
  • 1
    `error_page` directive should be in `@flask` location. Probably you'll also need `uwsgi_intercept_errors on;` there. – Alexey Ten May 03 '14 at 05:12

1 Answers1

2

error_page directive should be in @flask location. Probably you'll also need uwsgi_intercept_errors on; there.

Alexey Ten
  • 8,435
  • 1
  • 34
  • 36