Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Flask dev server over HTTPS using CLI

Tags:

python

flask

I am trying to serve a Flask application over HTTPS using the flask command. I can do this using app.run by passing the ssl_context argument, but I can't figure out how to do this on the CLI.

flask run --host='0.0.0.0' --port=80
like image 669
Bruce Pucci Avatar asked Jan 26 '18 18:01

Bruce Pucci


People also ask

How do I run a flask server with https?

In a Flask application, there are two ways through which we can build the Flask application and launch it through HTTPS. One of the methods is using ssl_context in the main() section of the code, and the other is through the command-line interface using the –cert option.

How do I run a flask app from the command line?

To run the app outside of the VS Code debugger, use the following steps from a terminal: Set an environment variable for FLASK_APP . On Linux and macOS, use export set FLASK_APP=webapp ; on Windows use set FLASK_APP=webapp . Navigate into the hello_app folder, then launch the program using python -m flask run .

How do I run a flask development server?

Starting development server: Starting a development server in the flask using the following command. Here <name> is the name of the file where the instance of the flask app has been created and the app. run() function exists. By convention, this file is mostly named app, thus the command will be shown below.

How do I make my flask server public?

Today, there are two ways to expose your flask application to the internet. Deploy the web application in your office server which has a public IP address and domain name. Deploy the web application in the cloud such as AWS, MS Azure, GCP or web hosting companies like GoDaddy, SiteGround, A2Hosting etc.


2 Answers

This will be available when Flask 1.0 is released.

flask run --cert dev.crt --key dev.key

Until then, use app.run if you really need this. Keep in mind that the dev server is not meant for production and should typically not be accessible publicly, so SSL shouldn't be as big a concern.

like image 200
davidism Avatar answered Oct 18 '22 22:10

davidism


I would personally use something like ngrok to create secure tunnels to localhost. Like davidism stated the dev server isn't meant for production but if you want see how your app behaves and/or your app requires SSL (like FlaskAsk apps for example) ngrok is the probably the easiest way.

like image 27
BrettJ Avatar answered Oct 18 '22 21:10

BrettJ