Deploy the FastAPI app on Debian with Nginx, Uvicorn, and Systemd.
3 min readMay 15, 2023
Last week, I was exploring the options to deploy the FastAPI project on the VPS, and I found that it’s super easy to deploy the FastAPI app.
I will share a quick step-by-step guide that will cover the following :
- A domain configured with Nginx reverse proxy
- FastAPI app inside a virtual environment
- And also a background service that will ensure the app is always running even after a reboot.
Let’s start with Nginx. We will create a site-available config file for our app domain.
sudo nano /etc/nginx/sites-available/myappdomain.com
server {
listen 80;
server_name www.myappdomain.com myappdomain.com;
location / {
proxy_pass http://127.0.0.1:8000; # should match with the fastapi port
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
To enable the domain/site, we need to create a symbolic link to the site-available config file in the site-enabled directory of Nginx.
sudo ln -s /etc/nginx/sites-available/myappdomain.com /etc/nginx/sites-enabled/