fastapi-101/
│
├── src/
│ ├── main.py
│ │
│ └── api_v1/
│ ├── __init__.py
│ ├── api.py
│ └── endpoints/
│ ├── __init__.py
│ ├── auth.py
│ ├── models.py
│ └── ai_function.py
│
├── requirements.txt
│
├── dockerfile
│
├── docker-compose.yml
│
└── README.md
- Build docker image
bash docker_build.sh- Deploy your service
docker-compose up -d- Firewall configuration
- Open port 8888 (not safe)
- Nginx reverse proxy configuration
-
Open port 80, 443
-
Use your domain / subdomain
-
Create a file named with your domain, put it under
/etc/nginx/sites-available/
// yourdomain.com
server {
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
- Create a soft link under
/etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/- Test and restart Nginx to make it work
sudo nginx -t
sudo service nginx restart- Then you can enter
http://<your-ip>:8888/docsto view the API Docs
For security, users should authorized to call your API.
