Description:
When running FastAPI behind a proxy (e.g., Nginx) with a path prefix like /inference/newmodel2-23/, we use the root_path parameter and X-Forwarded-Prefix headers. While the internal /docs handler works perfectly, manual implementations using get_swagger_ui_html result in a 404 for the openapi.json file because the proxy prefix is missing from the generated HTML.
Internal FastAPI Context
Looking at the FastAPI source:
https://github.com/fastapi/fastapi/blob/a456e92a21d5b94a67d6d0fd070218df09444443/fastapi/applications.py#L1093-L1107
Your source code
|
async def docs(self) -> HTMLResponse: |
|
openapi_url = "/v2/docs/dataplane.json" |
|
title = "MLServer API Docs" |
|
return get_swagger_ui_html(openapi_url=openapi_url, title=title) |
Expected Behavior
get_swagger_ui_html should ideally have an optional request parameter or a way to automatically detect and prepend the root_path so that documentation ui and routes work when behind a proxy.
Environment (docker containers)
- MLflow image: ghcr.io/mlflow/mlflow:v3.8.1
- Proxy: Nginx
Example Nginx Config
server {
listen 8983;
server_name localhost;
location /inference/newmodel2-23 {
proxy_pass http://fastapi:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Prefix /inference/newmodel2-23;
}
}
Description:
When running FastAPI behind a proxy (e.g., Nginx) with a path prefix like
/inference/newmodel2-23/, we use theroot_pathparameter andX-Forwarded-Prefixheaders. While the internal/docshandler works perfectly, manual implementations usingget_swagger_ui_htmlresult in a 404 for theopenapi.jsonfile because the proxy prefix is missing from the generated HTML.Internal FastAPI Context
Looking at the FastAPI source:
https://github.com/fastapi/fastapi/blob/a456e92a21d5b94a67d6d0fd070218df09444443/fastapi/applications.py#L1093-L1107
Your source code
MLServer/mlserver/rest/endpoints.py
Lines 44 to 47 in a325e52
Expected Behavior
get_swagger_ui_htmlshould ideally have an optionalrequestparameter or a way to automatically detect and prepend theroot_pathso that documentation ui and routes work when behind a proxy.Environment (docker containers)
Example Nginx Config