Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production environment vs dev #2

Closed
BE-Code opened this issue May 12, 2022 · 1 comment
Closed

Production environment vs dev #2

BE-Code opened this issue May 12, 2022 · 1 comment

Comments

@BE-Code
Copy link
Contributor

BE-Code commented May 12, 2022

At the bottom of the readme, there are some commands to get started with development. How would that be different for a production environment?

@exciteabletom
Copy link
Owner

Pretty much the same, except instead of using flask run to start the dev server you would use a production stack.

There are a myriad of problems with the Flask dev server that make it unsuitable for an internet facing server. Such as:

An example of a production stack you can use to replace the Flask server is Gunicorn and Nginx.

A flow chart looks like this: Web request -> Nginx -> Gunicorn -> Flask

Here's a very simplified explanation to help you get the concepts down:

Think of Nginx as a security guard. It handles all of the traffic coming from the public internet and ensures that your application is not being swamped by too many spam requests.

Flask does not handle HTTP requests directly, it uses the WSGI standard to understand HTTP requests. Gunicorn acts as a translator, turning the HTTP requests into the WSGI format for Flask.

Finally, your Flask app:

  • receives the WSGI request from Gunicorn
  • manipulates it as specified in your Python code
  • and sends a response back up the chain: Flask -> Gunicorn -> Nginx -> internet.

If you're looking for a tutorial the Gunicorn documentation is really good.

I know this is a bit overwhelming! If you're anything like me you will find it very difficult at first, but just know that one day it will all click and you will feel like this :P

Best of luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants