71

I see people are running setups like Nginx + Gunicorn + Flask.

Can someone explain what is the benefit of having Gunicorn in front of Flask? Why not just run Flask alone? Doesn't it consume more resources having Gunicorn + Flask running? Is Gunicorn able to reboot the Flask instance when it fails to respond?

What's also the purpose of having nginx on top of gunicorn? Isn't gunicorn enough? Again, more resources being spent?

3

1 Answer 1

73

I think you may be confused, Flask is not a web server, it is a framework and needs some sort of web server, such as Gunicorn, Nginx or Apache, to accept HTTP requests which it will then operate on. The reason why people run Nginx and Gunicorn together is that in addition to being a web server, Nginx can also proxy connections to Gunicorn which brings certain performance benefits, here is a pretty good answer that elaborates on those benefits: https://serverfault.com/questions/220046/why-is-setting-nginx-as-a-reverse-proxy-a-good-idea

EDIT: Added link containing information about performance benefits of running Nginx as a proxy.

4
  • 6
    If the Flask it self is not a web server, does it come shipped with some basic web server so that we can start it and access it via HTTP (default port 5000), docs? Although at the beginning they mention "The flask object implements a WSGI application", can WSGI applications talk HTTP directly and optionally via a proxy pass from a web server? This talks about WSGI servers...
    – NikoNyrh
    Commented Sep 30, 2015 at 7:56
  • 8
    Ahaa, at Deployment Options they mention "You can use the builtin server during development, but you should use a full deployment option for production applications".
    – NikoNyrh
    Commented Sep 30, 2015 at 8:17
  • 5
    Yes, flask by default uses the Werkzeug wsgi server, altough not as efficient as the Gunicorn server, it is easily a good testing and staging server.
    – ffleandro
    Commented Nov 1, 2017 at 22:11
  • This answer still pop up high in search, so here's an updated Deployment Options link from NikoNyrh's comment.
    – shayaan
    Commented Jun 25, 2020 at 0:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.