【问题标题】:How do i choose a runtime environment when using new-azwebapp?使用 new-azwebapp 时如何选择运行时环境?
【发布时间】:2019-09-09 12:03:54
【问题描述】:

我目前正在构建一个脚本来自动创建一个 azure Web 应用程序。前端是内置的 react 和部署良好。后端是使用节点构建的,并且在发布时不会运行。我认为默认情况下 New-AzWebApp 创建一个 .net windows 运行时环境,我想要一个 linux node.js 环境。我需要知道如何在 azure powershell 脚本中进行设置。

我已经尝试在应用创建后更改应用设置。通过 Set-AzWebApp 将 WEBSITE_NODE_DEFAULT_VERSION 更改为 10.16.3

New-AzWebApp -Name backend$webappname -Location $location -AppServicePlan $webappname -ResourceGroupName discoverTest$workItemId `

这将创建应用程序,但上传文件时应用程序不会运行。我想我需要合适的运行环境,但我不知道如何设置。

【问题讨论】:

    标签: azure azure-powershell


    【解决方案1】:

    首先,确保您的资源组中有 Linux 应用服务计划。并在 Linux 上的 Azure 应用服务中查看 Supported Versions of Node.js10.16.3 可能不受支持。

    然后你可以试试下面的命令,我的示例使用10.14 node.js 版本。

    #Create a Linux web app
    New-AzWebApp -ResourceGroupName <ResourceGroupName> -Name <web-app-name> -AppServicePlan <linux-app-service-plan-name> 
    #set it with node.js 10.14 
    $config = Get-AzResource -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName "<web-app-name>" -ApiVersion 2018-02-01
    $config.Properties.linuxFxVersion = "NODE|10.14"
    $config | Set-AzResource -ApiVersion 2018-02-01 -Force
    

    【讨论】:

      【解决方案2】:

      这是在 Azure 中创建新 Web 应用的示例定义命令:

      New-AzWebApp
         [-ResourceGroupName] <String>
         [-Name] <String>
         [-Location] <String>
         [[-AppServicePlan] <String>]
         [[-SourceWebApp] <PSSite>]
         [[-TrafficManagerProfile] <String>]
         [-EnableContainerContinuousDeployment]
         [-IgnoreSourceControl]
         [-IgnoreCustomHostNames]
         [[-AppSettingsOverrides] <Hashtable>]
         [[-AseName] <String>]
         [[-AseResourceGroupName] <String>]
         [-IncludeSourceWebAppSlots]
         [-AsJob]
         [-DefaultProfile <IAzureContextContainer>]
         [-WhatIf]
         [-Confirm]
         [<CommonParameters>]
      

      -AseName是应用服务环境,可用于设置环境。

      参考:

      https://docs.microsoft.com/en-us/azure/app-service/environment/intro

      https://docs.microsoft.com/en-us/azure/app-service/app-service-web-app-cloning

      希望对你有帮助。

      【讨论】:

      • AppServiceEnvironment 是一个完全不同的概念,与 Web 应用的运行时配置无关。这个答案应该被删除。
      猜你喜欢
      • 2015-11-18
      • 2020-01-24
      • 2013-02-26
      • 1970-01-01
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多