[BUG] Unable to correctly reverse proxy FastAPI
See original GitHub issueDescribe the bug
When using FastAPI behind a proxy that adds path elements like /api/1.0/
, there is no way to correctly display the swagger
To Reproduce
- Configure a reverse proxy to send
/api/1.0/
to your FastAPI server - access swagger for the API
- Observe that all your objects are prefixed with
/api/1.0
See screenshot
Expected behavior
/api/1.0
should not be part of API documentation.
OpenAPI documents this here
There should be a way to configure Server URL to /api/1.0
like indicated in the examples.
Screenshots
Environment
- OS: alpine docker image
- FastAPI Version 0.54.1
- Python version 3.7.3
Additional context
Using Traefik as reverse proxy. Traefik like other proxies, has the ability to either :
Pass the request as-is with /api/1.0/
, or strip the part from the URL and put it in the X-Forwarded-Prefix
header. Maybe that could be used as the server URL for Swagger.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Behind a Proxy - FastAPI
Having a proxy with a stripped path prefix, in this case, means that you could declare a path at /app in your code,...
Read more >can't see fastAPI documentation with 2 main.py and 1 nginx ...
Using nginx as a reverse proxy, I can call the APIs with their own endpoints under a single port (8000), then nginx will...
Read more >tiangolo/fastapi - Gitter
This application is started and stopped per user task session to a particular port. I would like to use fastapi as a reverse...
Read more >Deploying Gunicorn — Gunicorn 20.1.0 documentation
Without this buffering Gunicorn will be easily susceptible to denial-of-service attacks. You can use Hey to check if your proxy is behaving properly....
Read more >Deploying an Asynchronous FastAPI on NGINX Unit
Traditional deployment methods use web servers behind a reverse proxy server, thus increasing the routing process. Nginx Unit is an ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was fixed/implemented by @rkbeatss in https://github.com/tiangolo/fastapi/pull/1596. 🎉
Available in FastAPI version
0.59.0
. 🚀New docs here: https://fastapi.tiangolo.com/advanced/behind-a-proxy/#additional-servers
Ah, you are right, I didn’t interpret your original issue description correctly.
You expected it to not contain the prefix and still work.
I have to investigate how the
servers
would interact with the rest.