Skip to main content
  1. My Blog Posts and Stories/

Deploy that Flask

··425 words·2 mins

Insert thought provoking question #

Ever wondered why flask always gives Do not use it in a production deployment when we do flask run??

Flask cmd screenshot of warning not to use in production
Warning for flask not to use in production

Flask docs to dissuade users from using flask run directly
Warning to not run flask directly

According to the flask website here, it is not particularly efficient, stable, or secure. Currently, I am still using the built-in flask run. Oh no is it time for me to update? Seems like the perfect time (Instead of studying for exams).

Deployment time #

So here I go in my journey to make this begins. But how do I even begin though?? Time to google. Maybe I’ll just go How to deploy flask server??

TLDR there are a few options:

  1. Waitress
  2. Nginx
  3. Gunicorn

So which one do I start first? Of course the easiest! So waitress it is!

Waitress attempt #

So This is what I had to do:

  1. run pip install waitress
  2. Then run waitress-serve --call 'flaskr:create_app'
from waitress import serve

# App logic here

#Run waitress here
if __name__ == '__main__':
    serve(wsgiapp, listen='*:8080')

For more information visit the waitress website.

I simply just need to install waitress and run that code for it to work correctly. However, life is not so simple ><. After running all those, my terminal just froze and nothing happened. Welp I guess it will not be so simple after all…….

Nginx attempt #

Well, what to do. Onward to the next one, so up next it is Nginx. After searching online, there were not many materials that covered how to use it together with flask and docker, so I decided to try my luck on youtube.

I found this amazing video that explained step by step how to do it. He went through step by step on how to do it and by following his instructions, I managed to get it to run correctly.

The link to the video is here.

However, there are some configurations that I need to make in order to make HTTPS work correctly. According to the documentation on HTTP. I just needed to add-in

server {
    listen              443 ssl;
    server_name         www.example.com;
    ssl_certificate     www.example.com.chained.crt;    //This line for the certificate
    ssl_certificate_key www.example.com.key;            //And this line for the private key
    ...
}

after adding this line, it started working and running in HTTPS. Yayyy it’s done! After testing the website it feels faster (Maybe it’s just me).

Finally, the past few days of scratching my head are finally over!! :D. Woohoo what can I say, one more new item to add to the list of things that I have to learn