Search code examples
pythonnginxdeploymentwsgigevent

Deploy flask in production with GeventWSGI and Nginx


i actually have a rest api written in python with flask and flaskrestful extension. I use gevent WSGI

def runserver():
api.debug = True
http_server = WSGIServer(('', 5000), api)
http_server.start()

All works like a charm on my machine. I want go in production on a linux vm,on the internet i searched for hours,i don't choosed mod_wsgi because gevent doesn't work properly with it,so i prefer use nginx.

On the internet i saw flask apps hosted with uWSGI,my answer is i need to use uWSGI? Even i use geventWSGI in my flask application? How to work with this? In case i don't need uWSGI,i only need to config nginx sites to pass the request properly to my flask app? I'm newbie to all this so i'm a little confused.

Thanks in advance


Solution

  • You can run Uwsgi in Gevent mode http://uwsgi-docs.readthedocs.org/en/latest/Gevent.html and then route all flask requests to it via nginx.

           server {
              listen 80;
              server_name customersite1.com;
              access_log /var/log/customersite1/access_log;
              location / {
              root /var/www/customersite1;
              uwsgi_pass 127.0.0.1:3031;
              include uwsgi_params;
              }
    

    see http://uwsgi-docs.readthedocs.org/en/latest/Nginx.html for more details