FastAPI is an ASGI application and needs an ASGI-capable production server. A Python hosting feature that only loads WSGI applications does not automatically provide the required deployment path.
IN THIS ARTICLE
What you need before you begin
Confirm the plan permits an ASGI server, persistent processes and proxy routing. Identify the application import path, virtual environment and assigned local port or socket.
01 Run FastAPI behind a production reverse proxy
Install the locked application dependencies in the intended environment. Set production configuration and secrets without exposing them through the public directory.
Start the application with a supported production ASGI command, using the correct module and app object. Leave development reload mode disabled.
Supervise the process through the approved server or panel service. Bind it to the internal endpoint expected by the reverse proxy rather than exposing an unnecessary public port.
Configure HTTPS at the appropriate edge, forwarding to the ASGI service. Set trusted proxy handling and path prefixes only for the actual topology.
Configure resource limits, private logs and a health check. Document how the service is restarted and how the previous release can be restored.
02 Example: run an ASGI service behind a local proxy
For a reviewed deployment where the reverse proxy runs on the same Linux server and main.py exports app, an approved supervisor can launch a command shaped like this. Replace the virtual-environment path, module and assigned port with actual service values.
/home/ACCOUNT/apps/api/.venv/bin/python -m uvicorn main:app \
--host 127.0.0.1 --port 8000 --workers 1 \
--proxy-headers --forwarded-allow-ips 127.0.0.1
Set the supervisor's working directory and protected environment for this project. The proxy must connect through the stated loopback address and overwrite the trusted forwarded headers. If it is on another host or in a different container network, use the topology-specific supported listener and trust configuration instead.
Expected result: the public HTTPS endpoint responds through the proxy, and the supervisor restores the service after a controlled stop. Leaving this command running in an interactive shell is not a complete production service.
Confirm the expected result
Call a normal endpoint through the public HTTPS hostname and verify the response. Restart the service through the supervisor and confirm it recovers without an interactive terminal.
Troubleshoot unexpected results
A proxy 502 may mean the process is not running, the upstream address is wrong or startup failed. Read the ASGI log before increasing proxy timeouts.
A common question
Can I deploy FastAPI by renaming it to a WSGI entry file?
No. The protocols differ. Use a supported ASGI integration or choose a plan that permits the required server process.