Before starting with this step by step you may want to read the articles dedicated to this matter in the FastAPI documentation about HTTPS and Deployments Concepts of FastAPI documentation.
Find the location where you installed it and make it an environmental variable or run it from the folder with the following command:
Code Block | ||||
---|---|---|---|---|
| ||||
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt |
For further understanding visit the Open SSL Documentation Site.
And that's it, now you have 2 files in the current folder named certificate.crt and privateKey.key (which are the names we specified on the command at step 2). We're gonna save those files for later on this tutorial.
Again, this tutorial is focused on Uvicorn since that's the web server provided for development and testing purposes for our web application. Follow the instructions bellow:
Go to uvicorn_server.py located at the root folder of S-API and modify
Code Block | ||||
---|---|---|---|---|
| ||||
uvicorn.run('app.webapp:app', port=SERVER_CONFIG.port, host=SERVER_CONFIG.host, reload=True, log_level=SERVER_CONFIG.logging.level.value, workers=SERVER_CONFIG.workers, server_header=False) |
adding the parameters ssl_keyfile and ssl_certfile as shown below
Code Block | ||||
---|---|---|---|---|
| ||||
uvicorn.run('app.webapp:app', port=SERVER_CONFIG.port, host=SERVER_CONFIG.host, reload=True, log_level=SERVER_CONFIG.logging.level.value, workers=SERVER_CONFIG.workers, server_header=False, ssl_keyfile="config/certs/privateKey.key", ssl_certfile="config/certs/certificate.crt") |
And that's it, now you can go to the usual localhost:8085 but this time with https protocol instead.
Related articles
Content by Label | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Page properties | ||
---|---|---|
| ||
|