Running the application on Gunicorn and uWSGI
The main reason why Flask applications start by running the flask run
command or by calling app.run()
in main.py
during development is because of the built-in WSGI server that the werkzeug
module has. However, there are limitations that this server possesses, such as its inability to respond to more requests from clients without slowing down and its incapability to maximize the resources of the production server. Moreover, the built-in server has several vulnerabilities, which pose security risks. For standard Flask applications, it is best to use another WSGI server for production, such as Gunicorn or uWSGI.
Let’s start by deploying our application to the Gunicorn server.
Using the Gunicorn server
Gunicorn is the most common WSGI-based HTTP server that runs on a POSIX environment. If Windows is the environment that’s used for development, it will be a requirement to deploy our application to a UNIX-based server with...