← All guides
FastAPI deployment guide
Deploy FastAPI on Ubuntu with Nginx and SSL
VPS
Short answer
A FastAPI service running as a managed Ubuntu service, reachable through HTTPS, with logs you can inspect.
Why this matters
The API runs with `uvicorn main:app --reload`, but dies after SSH closes or returns 502 through Nginx.
Walkthrough
- 01
Create a clean Python runtime
Use an isolated environment so dependency versions are controlled and deploys do not depend on global Python packages.
- Create a virtual environment on the server.
- Install from a locked requirements file or project manager.
- Store database URLs and API keys outside the repository.
- 02
Run ASGI workers behind systemd
Production FastAPI should run under a process supervisor, not an interactive shell.
- Use Gunicorn with Uvicorn workers for a normal VPS setup.
- Create a systemd service that starts on boot.
- Check `journalctl` logs before debugging Nginx.
- 03
Proxy traffic with Nginx
Nginx terminates SSL and forwards requests to the internal FastAPI port or socket.
- Keep FastAPI bound to localhost or a private socket.
- Set proxy headers so the app sees the original host and protocol.
- Add health checks before handing over the server.
Where RepoAssistant fits
Need the API live today? RepoAssistant deploys FastAPI on Ubuntu with Nginx, SSL, and a server runbook.