What is the purpose of using nginx with gunicorn?

Nginx is a reverse proxy for Gunicorn. Gunicorn serves your Flask app and Nginx sits in front of it and decides where a request should go. For example, if the incoming request is an http request Nginx redirects it to gunicorn, if it is for a static file, it serves it itself. Read more about how to use Nginx and Gunicorn and how to deploy them starting from here.


Gunicorn is an application server for running your python application instance.

NGINX is a reverse proxy. It accepts incoming connections and decides where they should go next. It is in front of Gunicorn.


Do you know why the Django mascot is a pony? The story is that Django comes with so many things you want: an ORM, all sorts of middleware, the admin site…​ "What else do you want, a pony?" Well, Gunicorn stands for "Green Unicorn" - obeythetestinggoat.com

  • Nginx is the front face for your server.
  • Gunicorn runs multiple django projects(each project is a wsgi application powered by Gunicorn) in a single server(say Ubuntu).

Every request comes to nginx and asks for which gunicorn application should it go and it redirects it.

NOTE - Gunicorn cannot serve static files automatically as your local django server does. So you will need nginx for that again.


Nginx has some web server functionality (e.g., serving static pages; SSL handling) that gunicorn does not, whereas gunicorn implements WSGI (which nginx does not).

... Wait, why do we need two servers? Think of Gunicorn as the application web server that will be running behind nginx – the front- facing web server. Gunicorn is WSGI-compatible. It can talk to other applications that support WSGI, like Flask or Django.

Source: https://realpython.com/blog/python/kickstarting-flask-on-ubuntu-setup-and-deployment/