FastAPI deployment guide

Deploy FastAPI on Ubuntu with Nginx and SSL

FastAPI is simple locally, but production needs a managed Python process, a reverse proxy, secrets, logs, and a restart strategy.

What is probably broken

The API runs with `uvicorn main:app --reload`, but dies after SSH closes or returns 502 through Nginx.

What production should look like

A FastAPI service running as a managed Ubuntu service, reachable through HTTPS, with logs you can inspect.

STEP 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.

STEP 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.

STEP 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.

Quick check

Is your app production-ready?

If you cannot tick all five, we can fix it. Send us the repo and we handle the rest.

  • ?Custom domain with HTTPS
  • ?Environment variables configured
  • ?Database wired and backed up
  • ?Auto-deploy on push
  • ?Smoke tested and live

Free checklist

Deploying this yourself?

Get the exact 5-step checklist we run before every deploy. No fluff, just the things that actually break.

No spam. Your email is only used to send the checklist.

Done-for-you deploy

Need the API live today? RepoAssistant deploys FastAPI on Ubuntu with Nginx, SSL, and a server runbook.

Fixed price per repo. 24h delivery or full refund. No hourly billing.

Deploy my app

Related guides