在Azure Functions的Docker容器中运行FastAPI应用遇404问题求助
解决Azure Functions Docker容器中FastAPI应用404错误的方案
修复FastAPI路由路径
你的FastAPI路由定义缺少开头的斜杠,这是导致路由无法被识别的核心问题之一。修改路由定义:@app.get("/hello/{name}")确认function.json配置
确保http触发器的route设置为"{*route}",让所有请求都能转发到FastAPI应用。示例配置如下:{ "scriptFile": "__init__.py", "bindings": [ { "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "req", "methods": ["get", "post"], "route": "{*route}" }, { "type": "http", "direction": "out", "name": "$return" } ] }检查host.json配置
调整http扩展的routePrefix为空字符串,避免Azure Functions默认的/api前缀干扰FastAPI路由:{ "version": "2.0", "extensions": { "http": { "routePrefix": "" } } }验证访问路径
容器启动后,直接访问http://<容器地址>:<端口>/hello/你的名字,无需添加额外前缀。
内容的提问来源于stack exchange,提问作者Vege Saurus
相关产品推荐
相关产品推荐

