Question

I usually run my Flask applications with uWSGI and an nginx in front of it.

But I was thinking that the same could be achieved with just supervisor and nginx, so I googled around and found a lot of posts on how to setup and the benefits of the uWSGI-supervisor-nginx stack. I've decided to turn to SO, risking getting axed online for such a question.

So what are the benefits of running a Flask application behind uWSGI, supervisor and nginx? Why does apparently no one run Flask applications with only supervisor?

Was it helpful?

Solution

An app server such as gnicorn or uWSGI (used to host the flask applications) is used with nginx. nginx is a reverse proxy server which acts as a middleman. This helps with load balancing - handling multiples requests efficiently by distributing workloads over the resources. On top of this, supervisor is just used to monitor and control the server processes (gunicorn or uWSGI in our example). From my understanding, the web server that comes with Flask (werkzeug server) is not production ready and should be used for development purposes only.

OTHER TIPS

It's all about performance. Usually servers build into frameworks like Flask or Django are design for development environment, when you can quickly and easily reload code which you changed.

When you are running your application in production environment you don't have to worry about debugging and reloading your code often. Your biggest concerns are performance, security and configuration. During setting up production environment you can choose between uWSGI, Gunicorn , mod_wsgi and many others.

You can find plenty of blog posts with benchmarks between them and choose one which works best for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top