Deploy flask app with nginx using gunicorn and supervisor

Rahul Nayak
Jan 4, 2018 · 3 min read
Image for post
Image for post
Block diagram

Install required packages

$ sudo apt-get install nginx supervisor python-pip python-virtualenv

Create a virtual environment

$ virtualenv .env
$ source .env/bin/activate

Create a Flask app

$ pip install Flask
$ pip install -r requirements.txt
$ python app.py

Setup Gunicorn

Gunicorn ‘Green Unicorn’ is a Python WSGI HTTP Server for UNIX.

$ pip install gunicorn
$ gunicorn app:app -b localhost:8000 &

Use supervisor

Supervisor allows to monitor and control a number of processes on UNIX-like operating systems.

$ sudo supervisorctl reread
$ sudo service supervisor restart
$ sudo supervisorctl status

Setup nginx

Nginx is an HTTP and reverse proxy server.

$ sudo vim /etc/nginx/conf.d/virtual.conf
$ sudo nginx -t
$ sudo service nginx restart
Image for post
Image for post

YML Innovation Lab

Imagine a non-billable team that’s daily RFP is to…

Rahul Nayak

Written by

Just a guy

YML Innovation Lab

Imagine a non-billable team that’s daily RFP is to experiment, break things, and embody the bleeding edge of technology. Enter YML’s Innovation Lab; a team of AI and machine learning experts dreaming up the future of technology.

Rahul Nayak

Written by

Just a guy

YML Innovation Lab

Imagine a non-billable team that’s daily RFP is to experiment, break things, and embody the bleeding edge of technology. Enter YML’s Innovation Lab; a team of AI and machine learning experts dreaming up the future of technology.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store