使用 Azure 资源管理器模板(ARM 模板)和 Cloud Shell 中的 Azure CLI 将应用部署到云,以便开始使用 Azure 应用服务。 资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 由于使用的是免费应用服务层,完成本快速入门不会产生费用。
若要完成本快速入门,需要一个包含有效订阅的 Azure 帐户。 如果没有 Azure 帐户,可以免费创建一个。
注意
从 ARM API 版本 2024-11-01 开始,站点默认 禁用 基本身份验证。 如果需要 ,用户可以手动启用它 。
跳到末尾
如果熟悉使用 ARM 模板,可选择此 按钮跳到末尾。 此按钮会在 Azure 门户中打开 ARM 模板。
在 Azure 门户中,选择“新建”来创建新的资源组,然后选择“查看 + 创建”按钮来部署应用。
使用 Azure 资源管理器模板(ARM 模板)和 Cloud Shell 中的 Azure CLI 将应用部署到云,以便开始使用 Azure 应用服务。 资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 由于使用的是免费应用服务层,完成本快速入门不会产生费用。
若要完成本快速入门,需要一个包含有效订阅的 Azure 帐户。 如果没有 Azure 帐户,可以免费创建一个。
注意
从 ARM API 版本 2024-11-01 开始,站点默认 禁用 基本身份验证。 如果需要 ,用户可以手动启用它 。
跳到末尾
如果熟悉使用 ARM 模板,可选择此 按钮跳到末尾。 此按钮会在 Azure 门户中打开 ARM 模板。
在 Azure 门户中,选择“新建”来创建新的资源组,然后选择“查看 + 创建”按钮来部署应用。
通过在 Azure Cli 中使用 Azure 资源管理器模板(ARM 模板)和 Azure CLI 将应用部署到云,开始使用 Azure 应用服务。 资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 要部署 Windows 容器应用,需要高级计划。 有关定价详细信息,请参阅应用服务定价页。
注意
从 ARM API 版本 2024-11-01 开始,站点默认 禁用 基本身份验证。 如果需要 ,用户可以手动启用它 。
跳到末尾
如果熟悉使用 ARM 模板,可选择此 按钮跳到末尾。 此按钮会在 Azure 门户中打开 ARM 模板。
在 Azure 门户中,选择“新建”来创建新的资源组,然后选择“查看 + 创建”按钮来部署应用。
查看模板
本快速入门中使用的模板来自 Azure 快速启动模板。 它在 Windows 上部署应用服务计划和应用服务应用。 它与 .NET Core、.NET Framework、PHP、Node.js 和静态 HTML 应用兼容。 对于 Java,请参阅创建 Java 应用。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.25.53.49325",
"templateHash": "16144177164140676603"
}
},
"parameters": {
"webAppName": {
"type": "string",
"defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
"minLength": 2,
"metadata": {
"description": "Web app name."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"sku": {
"type": "string",
"defaultValue": "F1",
"metadata": {
"description": "The SKU of App Service Plan."
}
},
"language": {
"type": "string",
"defaultValue": ".net",
"allowedValues": [
".net",
"html"
],
"metadata": {
"description": "The language stack of the app."
}
},
"helloWorld": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "true = deploy a sample Hello World app."
}
},
"repoUrl": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "Optional Git Repo URL"
}
}
},
"variables": {
"appServicePlanPortalName": "[format('AppServicePlan-{0}', parameters('webAppName'))]",
"gitRepoReference": {
".net": "https://github.com/Azure-Samples/app-service-web-dotnet-get-started",
"html": "https://github.com/Azure-Samples/html-docs-hello-world"
},
"gitRepoUrl": "[if(bool(parameters('helloWorld')), variables('gitRepoReference')[toLower(parameters('language'))], parameters('repoUrl'))]",
"configReference": {
".net": {
"comments": ".Net app. No additional configuration needed."
},
"html": {
"comments": "HTML app. No additional configuration needed."
}
}
},
"resources": [
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2023-01-01",
"name": "[variables('appServicePlanPortalName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('sku')]"
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-01-01",
"name": "[parameters('webAppName')]",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"siteConfig": "[variables('configReference')[parameters('language')]]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
"httpsOnly": true
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
]
},
{
"condition": "[contains(variables('gitRepoUrl'), 'http')]",
"type": "Microsoft.Web/sites/sourcecontrols",
"apiVersion": "2023-01-01",
"name": "[format('{0}/{1}', parameters('webAppName'), 'web')]",
"properties": {
"repoUrl": "[variables('gitRepoUrl')]",
"branch": "master",
"isManualIntegration": true
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
]
}
]
}
该模板中定义了两个 Azure 资源:
- Microsoft.Web/serverfarms:创建应用服务计划。
- Microsoft.Web/sites:创建应用服务应用。
为了便于你使用,此模板包含多个预定义的参数。 有关参数默认值及其说明,请参阅下表:
参数 | 类型 | 默认值 | DESCRIPTION |
---|---|---|---|
webAppName | 字符串 | webApp-<uniqueString> |
基于唯一字符串值的应用名称 |
appServicePlanName | 字符串 | webAppPlan-<uniqueString> |
基于唯一字符串值的应用服务计划名称 |
位置 | 字符串 | [resourceGroup().location] |
应用区域 |
sku | 字符串 | F1 |
实例大小(F1 = 免费层) |
语言 | 字符串 | .NET |
编程语言堆栈(.NET、php、node、html) |
helloWorld | 布尔 | False |
True = 部署“Hello World”应用 |
repoUrl | 字符串 | |
外部 Git 存储库(可选) |
本快速入门中使用的模板来自 Azure 快速启动模板。 它在 Linux 上部署应用服务计划和应用服务应用。 它与应用服务上所有受支持的编程语言兼容。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.5.6.12127",
"templateHash": "10602523904429381366"
}
},
"parameters": {
"webAppName": {
"type": "string",
"defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
"minLength": 2,
"metadata": {
"description": "Web app name."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"sku": {
"type": "string",
"defaultValue": "F1",
"metadata": {
"description": "The SKU of App Service Plan."
}
},
"linuxFxVersion": {
"type": "string",
"defaultValue": "DOTNETCORE|8.0",
"metadata": {
"description": "The Runtime stack of current web app"
}
},
"repoUrl": {
"type": "string",
"defaultValue": " ",
"metadata": {
"description": "Optional Git Repo URL"
}
}
},
"variables": {
"appServicePlanPortalName": "[format('AppServicePlan-{0}', parameters('webAppName'))]"
},
"resources": [
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2021-02-01",
"name": "[variables('appServicePlanPortalName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('sku')]"
},
"kind": "linux",
"properties": {
"reserved": true
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2021-02-01",
"name": "[parameters('webAppName')]",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true,
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
"siteConfig": {
"linuxFxVersion": "[parameters('linuxFxVersion')]",
"minTlsVersion": "1.2",
"ftpsState": "FtpsOnly"
}
},
"identity": {
"type": "SystemAssigned"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
]
},
{
"condition": "[contains(parameters('repoUrl'), 'http')]",
"type": "Microsoft.Web/sites/sourcecontrols",
"apiVersion": "2021-02-01",
"name": "[format('{0}/{1}', parameters('webAppName'), 'web')]",
"properties": {
"repoUrl": "[parameters('repoUrl')]",
"branch": "master",
"isManualIntegration": true
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
]
}
]
}
该模板中定义了两个 Azure 资源:
- Microsoft.Web/serverfarms:创建应用服务计划。
- Microsoft.Web/sites:创建应用服务应用。
为了便于你使用,此模板包含多个预定义的参数。 有关参数默认值及其说明,请参阅下表:
参数 | 类型 | 默认值 | DESCRIPTION |
---|---|---|---|
webAppName | 字符串 | webApp-<uniqueString> |
基于唯一字符串值的应用名称 |
appServicePlanName | 字符串 | webAppPlan-<uniqueString> |
基于唯一字符串值的应用服务计划名称 |
位置 | 字符串 | [resourceGroup().location] |
应用区域 |
sku | 字符串 | F1 |
实例大小(F1 = 免费层) |
linuxFxVersion | 字符串 | DOTNETCORE|9.0 |
"编程语言堆栈 | 版本" |
repoUrl | 字符串 | |
外部 Git 存储库(可选) |
本快速入门中使用的模板来自 Azure 快速启动模板。 它在 Windows 容器上部署应用服务计划和应用服务应用。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.25.53.49325",
"templateHash": "10193476814580854111"
}
},
"parameters": {
"appServiceWebAppName": {
"type": "string",
"defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
"minLength": 2,
"metadata": {
"description": "Web App name."
}
},
"appServicePlanName": {
"type": "string",
"defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
"minLength": 2,
"metadata": {
"description": "App Service Plan name."
}
},
"skuTier": {
"type": "string",
"defaultValue": "P1v3"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-01-01",
"name": "[parameters('appServiceWebAppName')]",
"location": "[parameters('location')]",
"tags": {
"[format('hidden-related:{0}', resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName')))]": "empty"
},
"properties": {
"siteConfig": {
"appSettings": [
{
"name": "PORT",
"value": "8080"
}
],
"appCommandLine": "",
"windowsFxVersion": "DOCKER|mcr.microsoft.com/dotnet/samples:aspnetapp"
},
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
]
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2023-01-01",
"name": "[parameters('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('skuTier')]"
},
"kind": "windows",
"properties": {
"hyperV": true
}
}
]
}
该模板中定义了两个 Azure 资源:
- Microsoft.Web/serverfarms:创建应用服务计划。
- Microsoft.Web/sites:创建应用服务应用。
为了便于你使用,此模板包含多个预定义的参数。 有关参数默认值及其说明,请参阅下表:
参数 | 类型 | 默认值 | DESCRIPTION |
---|---|---|---|
webAppName | 字符串 | webApp-<uniqueString> |
基于唯一字符串值的应用名称 |
appServicePlanName | 字符串 | webAppPlan-<uniqueString> |
基于唯一字符串值的应用服务计划名称 |
位置 | 字符串 | [resourceGroup().location] |
应用区域 |
skuTier | 字符串 | P1v3 |
实例大小(查看可用的 SKU) |
应用设置 | 字符串 | [{"name": "PORT","value": "8080"}] |
应用服务侦听端口。 需为 8080。 |
类型 | 字符串 | windows |
操作系统 |
hyperv | 字符串 | true |
隔离模式 |
windowsFxVersion | 字符串 | DOCKER|mcr.microsoft.com/dotnet/samples:aspnetapp |
容器映像 |
部署模板
此处使用 Azure CLI 来部署模板。 还可以使用 Azure 门户、Azure PowerShell 和 REST API。 若要了解其他部署方法,请参阅部署模板。
以下代码将创建一个资源组、一个应用服务计划和一个 Web 应用。 系统会为你设置默认资源组、应用服务计划和位置。 请将 <app-name>
替换为全局唯一的应用名称(有效字符是 a-z
、0-9
和 -
)。
运行以下命令,在 Windows 上部署 .NET Framework 应用。
az group create --name myResourceGroup --location "chinaeast" &&
az deployment group create --resource-group myResourceGroup \
--parameters language=".NET" helloWorld="true" webAppName="<app-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-windows/azuredeploy.json"
运行以下命令,在 Linux 上创建 Python 应用:
az group create --name myResourceGroup --location "chinaeast" &&
az deployment group create --resource-group myResourceGroup --parameters webAppName="<app-name>" linuxFxVersion="PYTHON|3.9" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-linux/azuredeploy.json"
若要部署其他语言堆栈,请使用相应的值更新 linuxFxVersion
。 示例如表所示。 若要显示当前版本,请在 Azure CLI 中运行以下命令:az webapp config show --resource-group myResourceGroup --name <app-name> --query linuxFxVersion
az webapp config show --resource-group myResourceGroup --name <app-name> --query linuxFxVersion
语言 | 示例: |
---|---|
.NET | linuxFxVersion=“DOTNETCORE|9.0” |
爪哇岛 | linuxFxVersion=“JAVA|21-java21 TOMCAT|11.0-java21 JBOSSEAP|8-java17” |
Node.js | linuxFxVersion="NODE|22-lts |
Python | linuxFxVersion=“PYTHON|3.13” |
PHP | linuxFxVersion=“PHP|8.4” |
运行以下命令,在 Windows 容器上部署 .NET 应用。
az group create --name myResourceGroup --location "chinanorth2"
az deployment group create --resource-group myResourceGroup \
--parameters webAppName="<app-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-windows-container/azuredeploy.json"
注意
验证部署
浏览到 http://<app_name>.chinacloudsites.cn/
并验证它是否已创建。
清理资源
不再需要资源组时,可将其删除。
后续步骤
从本地 Git 进行部署
将 Python 与 Postgres 配合使用