首页 > 解决方案 > 从 Node.js 创建 WebApp 资源时,“参数 LinuxFxVersion 的值无效”

问题描述

我正在尝试在 Node.js 环境中使用 Azure SDK for JS 创建一个简单的 WebApp,但我不断收到响应:

{
  "Code":"BadRequest",
  "Message":"The parameter LinuxFxVersion has an invalid value.",
  "Target":null,
  "Details":[
    {"Message":"The parameter LinuxFxVersion has an invalid value."},
    {"Code":"BadRequest"},
    {"ErrorEntity": {
        "ExtendedCode":"01007",
        "MessageTemplate":"The parameter {0} has an invalid value.",
        "Parameters":["LinuxFxVersion"],
        "Code":"BadRequest",
        "Message":"The parameter LinuxFxVersion has an invalid value."}
    }],
  "Innererror":null
}

我尝试了各种不同的属性和环境集,但都没有成功。我总是收到这个错误。这是我正在使用的 TypeScript 代码片段:

    const wsmClient: WebSiteManagementClient...
    const webAppName: string...
    const servicePlanId: string...
    const rgName: string...
    const envelope: Site = {
      name: webAppName,
      location: 'westus2',
      kind: 'app,linux',
      serverFarmId: servicePlanId,
      siteConfig: {
        linuxFxVersion: 'JAVA|11-java11'
      }
    };
    const appResp = await wsmClient.webApps.createOrUpdate(
      rgName,
      webAppName,
      envelope
    );

我究竟做错了什么?

标签: azureazure-web-app-service

解决方案


原因

您的应用服务计划不是 Linux,实际上是 Windows。Windows 主机没有参数 LinuxFxVersion。

如果我们创建站点时没有将主机显式配置为 Linux,则默认情况下它将是 Windows 主机/serverFarm/app 服务计划。使用 {"kind":"linux"} 是不够的。

解决方案

在 Linux 中明确定义应用服务计划,并确保{"reserved": true}将其设置为 Linux 主机(参见文档

{
    "type": "Microsoft.Web/serverfarms",
    "apiVersion": "2019-08-01",
    "name": "[parameters('hostingPlanName')]",
    "location": "[parameters('location')]",
    "kind": "app,linux",
    "properties": {
        "reserved": true
    },
    "sku": {
        "Tier": "[parameters('hostingPlanSkuTier')]",
        "Name": "[parameters('hostingPlanSkuName')]"
    }
}

推荐阅读