
FastAPI speaks ASGI, and the server that runs it is uvicorn. On a VPS, the production recipe has four pieces: uvicorn with a few processes, a systemd service that keeps it alive, nginx in front with HTTPS, and the application listening only on 127.0.0.1. The basics (running with uvicorn main:app) are already in running a Flask or FastAPI application; what follows is what turns it into a proper service.
From test to service
|
|
|
|
The details that make a difference
| Topic | What to know |
| The visitor’s address | Behind the proxy, the API sees nginx’s IP. uvicorn reads X-Forwarded-For from the addresses it trusts (--forwarded-allow-ips, by default only the server itself, which suits a local nginx). |
| Automatic documentation | FastAPI publishes /docs and /redoc. For a private API, switch them off: FastAPI(docs_url=None, redoc_url=None). |
| Long tasks | A request that takes long holds a process. For heavy work, do it outside the request (a queue), instead of raising the workers. |
| Websockets | FastAPI supports them. For nginx, see WebSockets on a VPS. |
| Cross-origin requests | If a site on another domain calls this API: CORS. |
Do not expose uvicorn to the Internet. Listening on 0.0.0.0 with the port open in the firewall skips HTTPS and the proxy. Keep 127.0.0.1 and leave only nginx public. If the API does not answer from outside, follow ports and firewall on a VPS.
|
Create a health route (for example /health answering “ok”) and use it to know whether the API is alive: with curl, or in a monitoring service. If the service will not start, journalctl -u my-api -n 100 says why. On an unmanaged VPS the maintenance is yours: how far our support goes.
|
|
Need a server for your API? Have a look at our VPS plans. See the VPS servers |
|
SEE ALSO Running Flask or Django with gunicorn and systemd on a VPS Nginx as a reverse proxy in front of a container CORS error between your front end and your API: how to fix it |
RECOMMENDED PRODUCT VPS server with root access Resources of your own, the OS you choose, reinstall whenever you like. from $8.39/mo (3-year plan, with coupon) See plans |
- 0 Users Found This Useful











