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

PythonNginxFlaskGunicorn

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKJWView Question on Stackoverflow
Solution 1 - PythonJonView Answer on Stackoverflow