What benefit is added by using Gunicorn + Nginx + Flask? [duplicate]
Asked Answered
N

1

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?

Nev answered 24/12, 2013 at 21:0 Comment(3)
Gunicorn is a Python WSGI HTTP Server that usually lives between a reverse proxy (e.g., Nginx) or a load balancer (e.g., AWS ELB) and a web application such as Django or Flask. good article: medium.com/building-the-system/…Nakashima
See this for more - serverfault.com/a/331263/564406Adamok
And this - vsupalov.com/gunicorn-and-nginxAdamok
M
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.

Mohican answered 24/12, 2013 at 21:31 Comment(4)
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...Lesleylesli
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".Lesleylesli
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.Edmonson
This answer still pop up high in search, so here's an updated Deployment Options link from NikoNyrh's comment.Somatist

© 2022 - 2024 — McMap. All rights reserved.