What benefit is added by using Gunicorn + Nginx + Flask?

25,680

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.

Share:
25,680
KJW
Author by

KJW

It's about how hard you can take a hit and still move forward.

Updated on February 19, 2020

Comments

  • KJW
    KJW about 4 years

    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?

  • NikoNyrh
    NikoNyrh over 8 years
    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
    NikoNyrh over 8 years
    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".
  • ffleandro
    ffleandro over 6 years
    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.
  • shayaan
    shayaan almost 4 years
    This answer still pop up high in search, so here's an updated Deployment Options link from NikoNyrh's comment.