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

Azure App Service Linux环境下.NET Core 8.0应用404问题求助

问题描述

在Azure App Service Linux环境部署.NET Core 8.0应用,已配置linuxFxVersion: 'DOTNETCORE:8.0'以及App Service Plan的reserved: true,但访问时持续收到Nginx返回的HTTP 404错误。该应用在Windows环境的App Service中运行正常,查看日志却发现App Service正在下载PHP 8.0.x镜像,而非预期的.NET Core镜像。

ARM模板代码

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  sku: environmentConfigurationMap[environment].appServicePlan.sku
  properties: {
    reserved: true
  }
  kind: 'linux'
}

resource appServiceApp 'Microsoft.Web/sites@2022-03-01' = {
  name: appServiceAppName
  location: location
  identity: { type: 'SystemAssigned' }
  properties: {
    serverFarmId: appServicePlan.id
    httpsOnly: true
    siteConfig: {
      linuxFxVersion: 'DOTNETCORE:8.0'
      // netFrameworkVersion: 'v8.0'
      appSettings: [
        {
          name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
          value: applicationInsights.properties.InstrumentationKey
        }
        {
          name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
          value: applicationInsights.properties.ConnectionString
        }
      ]
    }
  }
}

错误日志截图

日志显示正在下载PHP镜像
Nginx返回HTTP 404错误
应用启动日志异常

解决方案
  • 检查SKU兼容性:确认使用的App Service Plan SKU支持Linux容器部署,部分基础SKU可能存在镜像拉取异常,可临时切换到B1及以上SKU测试。
  • 强制刷新运行时配置:通过Azure CLI执行命令,强制指定.NET Core 8.0运行时,避免配置未生效:
    az webapp config set --name <你的应用名称> --resource-group <资源组名称> --linux-fx-version "DOTNETCORE:8.0"
    
  • 清理旧镜像缓存:进入App Service的Kudu高级工具,在Docker标签页清理已下载的PHP镜像,随后重启应用。
  • 显式声明模板依赖:在ARM模板的Web App资源中添加dependsOn,确保App Service Plan完全部署后再创建Web App,避免配置未被正确应用:
    resource appServiceApp 'Microsoft.Web/sites@2022-03-01' = {
      name: appServiceAppName
      location: location
      identity: { type: 'SystemAssigned' }
      dependsOn: [appServicePlan] // 添加该行声明依赖
      properties: {
        // 原有属性内容...
      }
    }
    
  • 验证部署包完整性:确认上传的部署包是.NET Core 8.0的正确构建输出,包含Program.cs、web.config(若需)等核心文件,避免因部署包缺失导致运行时无法识别应用类型。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 06:28:13