问题
I am currently building a script to automate the creation of an azure web app. The frontend is built in react and deploys fine. The backend is built using node and doesnt run when its been published. I think that by default New-AzWebApp creates a .net windows runtime environment and i want a linux node.js environment. I need to know how to set this in an azure powershell script.
I've already tried to alter the App Settings after the app has been created. Changing the WEBSITE_NODE_DEFAULT_VERSION to 10.16.3 via Set-AzWebApp
New-AzWebApp -Name backend$webappname -Location $location -AppServicePlan $webappname -ResourceGroupName discoverTest$workItemId `
This will create the app but when the files are uploaded the app doesn't run. I think i need the right runtime environment, but i don't know how to set it.
回答1:
First, make sure you have a Linux App Service Plan in your resource group. And see the Supported Versions of Node.js in Azure App Service on Linux, the 10.16.3 may not be supported.
Then you can try the commands as below, my sample uses a 10.14 node.js version.
#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:
Here is the sample definition command for creating new web app in Azure:
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 is the app service environment which you can use for setting the environment.
Reference:
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
Hope it helps.
来源:https://stackoverflow.com/questions/57821251/how-do-i-choose-a-runtime-environment-when-using-new-azwebapp