Docs / Programming & Development / How to Deploy FastAPI with Uvicorn and Nginx

How to Deploy FastAPI with Uvicorn and Nginx

By Admin · Mar 1, 2026 · Updated Apr 23, 2026 · 29 views · 1 min read

What Is FastAPI?

FastAPI is a modern Python web framework for building APIs. It leverages async capabilities and automatic OpenAPI documentation. Deploying FastAPI on your Breeze with Uvicorn as the ASGI server and Nginx as a reverse proxy provides a production-ready setup.

Prerequisites

  • A Breeze running Ubuntu 22.04 or later
  • Python 3.10+ installed
  • Nginx installed

Step 1: Set Up the Project

cd /var/www/fastapi-app
python3 -m venv venv
source venv/bin/activate
pip install fastapi uvicorn gunicorn

Step 2: Create a Systemd Service

sudo nano /etc/systemd/system/fastapi.service
[Unit]
Description=FastAPI Application
After=network.target

[Service]
User=www-data
WorkingDirectory=/var/www/fastapi-app
ExecStart=/var/www/fastapi-app/venv/bin/gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 127.0.0.1:8000
Restart=always

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now fastapi

Step 3: Configure Nginx

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
sudo ln -s /etc/nginx/sites-available/fastapi /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Step 4: Enable SSL

sudo certbot --nginx -d yourdomain.com

Performance Tips

Adjust the -w flag to match your Breeze CPU count. Use --access-logfile - to log requests to stdout for monitoring with journalctl.

Was this article helpful?