Last Updated: February 25, 2016
·
1.158K
· jbradach

Nginx configuration for a Flask app with a uWSGI upstream

A sample Nginx server block configuration to deploy a <a href="https://lemp.io/qa/question/deploying-flask-applications-on-lemp/">Flask application</a> using uWSGI. Uses Nginx's <a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html">upstream directive</a> and supports <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#listen">IPv6</a>.

upstream uwsgi_host {
    server unix:/tmp/flaskapp.sock;
}

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;

  location ^~ /static/ {
      alias /srv/www/flaskapp/app/static;
  }

  location / { try_files $uri @flaskapp; }
  location @flaskapp {
      include uwsgi_params;
      uwsgi_pass uwsgi_host;
  }
}