FastAPI fundamentals

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.

pip install fastapi
pip install uvicorn
uvicorn main:app

Some words about Nginx

Deployment steps

ssh -i Downloads/fastapi-nginx.cer ubuntu@ec2-18-116-199-161.us-east-2.compute.amazonaws.com
git clone https://github.com/lcalcagni/Deploying-FastAPI-using-Nginx.git
cd Deploying-FastAPI-using-Nginxsudo apt-get updatesudo apt install python3-pippip3 install -r requirements.txt
python3 -m uvicorn main:app
sudo apt install nginx
cd /etc/nginx/sites-enabled/sudo nano fastapi_nginx

server {
listen 80; server_name 18.116.199.161; location / { proxy_pass http://127.0.0.1:8000; }}
sudo service nginx restart
cd path/to/Deploying-FastAPI-using-Nginxpython3 -m uvicorn main:app
sudo apt-get install opensslcd /etc/nginx
sudo mkdir ssl
sudo openssl req -batch -x509 -nodes -days 365 \-newkey rsa:2048 \-keyout /etc/nginx/ssl/server.key \-out /etc/nginx/ssl/server.crt
cd /etc/nginx/sites-enabled/sudo nano fastapi_nginx
server {    listen 80;    listen 443 ssl;    ssl on;    ssl_certificate /etc/nginx/ssl/server.crt;    ssl_certificate_key /etc/nginx/ssl/server.key;
server_name 18.116.199.161; location / { proxy_pass http://127.0.0.1:8000; }}
sudo service nginx restart
cd path/to/Deploying-FastAPI-using-Nginxpython3 -m uvicorn main:app
return 301 https://$server_name$request_uri;

sudo service nginx restart
Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐