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

Azure App Service(Linux)部署ASP.NET Core 8 API遇403/404错误求助

排查Azure Linux App Service部署ASP.NET Core 8后403/404及php-fpm启动问题
  • 修正App Service运行时配置
    核心问题是App Service启动了PHP运行时而非.NET,根源在于linuxFxVersion配置错误。

    • 在Bicep代码中,确保App Service的siteConfig指定正确的.NET 8运行时:
      resource appService 'Microsoft.Web/sites@2023-01-01' = {
        name: appServiceName
        location: location
        properties: {
          serverFarmId: serverFarm.id
          siteConfig: {
            linuxFxVersion: 'DOTNETCORE|8.0'
            appSettings: [
              {
                name: 'ASPNETCORE_ENVIRONMENT'
                value: 'Production'
              }
            ]
          }
        }
      }
      
    • 若已完成部署,可直接在Azure Portal进入App Service → 配置 → 常规设置,将运行时堆栈改为.NET 8,保存后重启服务。
  • 检查GitHub Actions部署任务
    确保部署任务针对.NET应用,且指向正确的发布目录:

    - name: Deploy to Azure Web App
      uses: azure/webapps-deploy@v2
      with:
        app-name: ${{ env.AZURE_WEBAPP_NAME }}
        publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
        package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/bin/Release/net8.0/publish/
        app-type: webAppLinux
    

    确认package路径是ASP.NET Core项目发布后的输出目录,避免因部署错误文件导致运行时识别异常。

  • 验证启动进程与日志

    • 检查App Service的启动命令,若有自定义命令,确保格式为dotnet YourApiAssemblyName.dll(替换为你的API程序集名称);若无自定义命令,默认.NET启动逻辑会自动加载入口程序集。
    • 通过Azure Portal的「日志流」查看启动日志,确认出现Now listening on: http://[::]:80字样,说明.NET应用已成功启动,替代之前的php-fpm日志。
  • 排查/test端点404问题

    • 确认控制器路由配置正确,示例:
      [ApiController]
      [Route("test")]
      public class TestController : ControllerBase
      {
          [HttpGet]
          public IActionResult Get()
          {
              return Ok("Success");
          }
      }
      
    • 检查部署包中是否包含完整的appsettings.json和程序集文件,缺失配置或文件可能导致路由初始化失败。

内容的提问来源于stack exchange,提问作者Stefan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 11:42:41