Running a Flask app with nginx

I just read an overly complicated blog post on how to use nginx with Flask and wanted to tell the simple story so it wouldn't scare people away from using two of my favorite tools.

It is amazingly simple to do this.

Prerequisites:

  • Have Flask installed (use pip).
  • Have Gunicorn installed (use pip).
  • Have nginx installed (should be in your package manager).

Write a Flask app.

Add this to your nginx config:

server {

    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:9999;
    }

}

Test your config and restart nginx:

sudo nginx -t
sudo nginx -s reload

Run your app under gunicorn:

gunicorn filename:appname -b 127.0.0.1:9999

That's all there is to it.

Comments !

blogroll

social