FastAPI Behind a Reverse Proxy: Fixing Docs URLs

A reverse proxy can hide the full URL from your FastAPI app, breaking OpenAPI docs. Tell your app about the proxy's path prefix by setting the `root_path` during initialization to ensure all generated URLs are correct.
Think of your app as an office that only knows its room number. A reverse proxy is the front desk, directing `example.com/api/v1/users` to your app's `/users` endpoint. This breaks OpenAPI docs, which need the full path. The footgun is that "Try it out" fails silently. Fix this by telling FastAPI the stripped prefix via `root_path`, like `FastAPI(root_path="/api/v1")`, so it can generate correct public-facing URLs.
Read the original → fastapi.tiangolo.com
- #fastapi
- #python
- #reverse-proxy
- #networking
- #openapi
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.