-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to correctly reverse proxy FastAPI #1294
Comments
You can use Ideally, it should be resolved dynamically based on the |
That's exactly my situation. Traefik passes all the information but they are not leveraged by fastapi. I switched to Connexion since then |
Related to #829. @ybizeul raises a good point that the application's root path should probably be included in a server object in the generated OpenAPI documentation and omitted from the routes in the API. FastAPI's current behavior (not specifying a
So equivalent to: servers:
- url: '/' |
Passing the Available in FastAPI Here are new docs on running FastAPI Behind a Proxy with a Traefik example. It could be passed to Uvicorn as: $ uvicorn app:main --root-path=/api/1.0 About reading the If it is implemented there, it will be automatically supported here. |
From what I see in the documentation you point me to, it's not fixed at all and |
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 |
This was fixed/implemented by @rkbeatss in #1596. 🎉 Available in FastAPI version New docs here: https://fastapi.tiangolo.com/advanced/behind-a-proxy/#additional-servers |
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues. |
Hi, I am still stuck in FastAPI behind Reverse Proxy Nginx.
But when running FastAPI behind the proxy, the ROOT_PATH is double before the endpoint which causes the query to be wrongly directed.
Here is FastAPI app config app = FastAPI(
root_path = "/ge_api",
description = desc,
openapi_tags = tags_metadata,
version = "0.0.1",
docs_url = '/ge_api/docs',
redoc_url = '/ge_api/redoc',
openapi_url = '/ge_api/openapi.json',
) Nginx config:
Is there any fixed for the issue? Thanks |
I solved same issue using subapi:
|
@dontsovcmc:
@trungswat: I'm almost a year late on this, but the mistake you're making here is specifying |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
When using FastAPI behind a proxy that adds path elements like
/api/1.0/
, there is no way to correctly display the swaggerTo Reproduce
/api/1.0/
to your FastAPI server/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
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 theX-Forwarded-Prefix
header. Maybe that could be used as the server URL for Swagger.The text was updated successfully, but these errors were encountered: