Flask + Gunicorn + Supervisor + Nginx

This morning, I deployed a Flask application in a Ubuntu 13.04 server with Nginx and Gunicorn. Here is the configuration:

0. My app code base (blog):


1. I created a shell script to run gunicorn:



# user/group to run as
cd /projects/blog
/projects/.venv/blog/bin/gunicorn blog:app -w $NUM_WORKERS -b $ADDRESS

2. Supervisor configuration:


directory = /projects/blog/flaskr/
user = dangtrinhnt
command = /projects/blog/blogguni.sh
stdout_logfile = /projects/logs/supervisor_blog.log
stderr_logfile = /projects/logs/supervisor_blog_error.log

3. Nginx configuration:


upstream blog {
    server localhost:5000 fail_timeout=0;
server {
    listen 80;
    server_name dangtrinhnt.kd.io;
    access_log /projects/logs/access_blog.log;
    error_log /projects/logs/error_blog.log;
    location /static/ {
        alias /projects/blog/static/;
    location / {
        proxy_pass http://blog;

I used the Flaskr example from Flask project which you can find at https://github.com/mitsuhiko/flask/tree/master/examples/flaskr/

I deployed the blog in a free VM provided by Koding at https://koding.com/?r=dangtrinhnt
(you can get a free one too).

The blog is now live at http://dangtrinhnt.kd.io/ (only when I'm actively logging in Koding)

It's pretty cool!!!