You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 15:39:20