你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
使用 Azure 资源管理器模板创建应用服务应用并部署专用终结点
在本快速入门中,使用 Azure 资源管理器 (ARM) 模板创建 Web 应用,并使用专用终结点公开该 Web 应用。
Azure 资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 模板使用声明性语法。 你可以在不编写用于创建部署的编程命令序列的情况下,描述预期部署。
先决条件
需要一个具有活动订阅的 Azure 帐户。 免费创建帐户。
创建专用终结点
该模板为 Azure Web 应用创建专用终结点。
查看模板
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualNetwork_name": {
"type": "String",
"metadata":{
"description": "Name of the VNet"
}
},
"serverFarm_name": {
"type": "String",
"defaultValue": "ServerFarm1",
"metadata":{
"description": "Name of the Web Farm"
}
},
"site_name": {
"type": "String",
"metadata":{
"description": "Web App name must be unique DNS name worldwide"
}
},
"virtualNetwork_CIDR": {
"type": "String",
"defaultValue": "10.200.0.0/16",
"metadata":{
"description": "CIDR of your VNet"
}
},
"subnet1_name": {
"type": "String",
"metadata":{
"description": "Name of the Subnet"
}
},
"subnet1_CIDR": {
"type": "String",
"defaultValue": "10.200.1.0/24",
"metadata":{
"description": "CIDR of your subnet"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata":{
"description": "Location for all resources."
}
},
"SKU_name": {
"type": "String",
"defaultValue": "P1v2",
"metadata":{
"description": "SKU name, must be minimum P1v2"
}
},
"SKU_tier": {
"type": "String",
"defaultValue": "PremiumV2",
"metadata":{
"description": "SKU tier, must be Premium"
}
},
"SKU_size": {
"type": "String",
"defaultValue": "P1v2",
"metadata":{
"description": "SKU size, must be minimum P1v2"
}
},
"SKU_family": {
"type": "String",
"defaultValue": "P1v2",
"metadata":{
"description": "SKU family, must be minimum P1v2"
}
},
"privateEndpoint_name": {
"type": "string",
"metadata":{
"description": "Name of your Private Endpoint"
}
},
"privateLinkConnection_name": {
"type": "string",
"metadata":{
"description": "Link name between your Private Endpoint and your Web App"
}
},
"privateDNSZone_name": {
"type": "string",
"defaultValue": "privatelink.azurewebsites.net",
"metadata":{
"description": "Name must be privatelink.azurewebsites.net"
}
},
"webapp_dns_name": {
"type": "string",
"defaultValue": ".azurewebsites.net",
"metadata":{
"description": "Name must be privatelink.azurewebsites.net"
}
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2020-04-01",
"name": "[parameters('virtualNetwork_name')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('virtualNetwork_CIDR')]"
]
}
}
},
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2020-04-01",
"name": "[concat(parameters('virtualNetwork_name'),'/', parameters('subnet1_name'))]",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetwork_name'))]"
],
"properties": {
"addressPrefix": "[parameters('subnet1_CIDR')]",
"privateEndpointNetworkPolicies": "Disabled"
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2019-08-01",
"name": "[parameters('serverFarm_name')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('SKU_name')]",
"tier": "[parameters('SKU_tier')]",
"size": "[parameters('SKU_size')]",
"family": "[parameters('SKU_family')]",
"capacity": 1
},
"kind": "app"
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2019-08-01",
"name": "[parameters('site_name')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('serverFarm_name'))]"
],
"kind": "app",
"properties": {
"enabled": true,
"hostNameSslStates": [
{
"name": "[concat(parameters('site_name'), parameters('webapp_dns_name'))]",
"sslState": "Disabled",
"hostType": "Standard"
},
{
"name": "[concat(parameters('site_name'), '.scm', parameters('webapp_dns_name'))]",
"sslState": "Disabled",
"hostType": "Repository"
}
],
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('serverFarm_name'))]"
}
},
{
"type": "Microsoft.Web/sites/config",
"apiVersion": "2019-08-01",
"name": "[concat(parameters('site_name'), '/web')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('site_name'))]"
],
"properties": {
"ftpsState": "AllAllowed"
}
},
{
"type": "Microsoft.Web/sites/hostNameBindings",
"apiVersion": "2019-08-01",
"name": "[concat(parameters('site_name'), '/', parameters('site_name'), parameters('webapp_dns_name'))]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('site_name'))]"
],
"properties": {
"siteName": "[parameters('site_name')]",
"hostNameType": "Verified"
}
},
{
"type": "Microsoft.Network/privateEndpoints",
"apiVersion": "2019-04-01",
"name": "[parameters('privateEndpoint_name')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('site_name'))]",
"[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetwork_name'), parameters('subnet1_name'))]"
],
"properties": {
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetwork_name'), parameters('subnet1_name'))]"
},
"privateLinkServiceConnections": [
{
"name": "[parameters('privateLinkConnection_name')]",
"properties": {
"privateLinkServiceId": "[resourceId('Microsoft.Web/sites', parameters('site_name'))]",
"groupIds": [
"sites"
]
}
}
]
}
},
{
"type": "Microsoft.Network/privateDnsZones",
"apiVersion": "2018-09-01",
"name": "[parameters('privateDNSZone_name')]",
"location": "global",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetwork_name'))]"
]
},
{
"type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
"apiVersion": "2018-09-01",
"name": "[concat(parameters('privateDNSZone_name'), '/', parameters('privateDNSZone_name'), '-link')]",
"location": "global",
"dependsOn": [
"[resourceId('Microsoft.Network/privateDnsZones', parameters('privateDNSZone_name'))]",
"[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetwork_name'))]"
],
"properties": {
"registrationEnabled": false,
"virtualNetwork": {
"id": "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetwork_name'))]"
}
}
},
{
"type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
"apiVersion": "2020-03-01",
"name": "[concat(parameters('privateEndpoint_name'),'/dnsgroupname')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/privateDnsZones', parameters('privateDNSZone_name'))]",
"[resourceId('Microsoft.Network/privateEndpoints' , parameters('privateEndpoint_name'))]"
],
"properties": {
"privateDnsZoneConfigs": [
{
"name": "config1",
"properties": {
"privateDnsZoneId": "[resourceId('Microsoft.Network/privateDnsZones', parameters('privateDNSZone_name'))]"
}
}
]
}
}
]
}
部署模板
下面介绍如何将 Azure 资源管理器模板部署到 Azure:
- 若要登录到 Azure 并打开模板,请选择此链接:部署到 Azure。 使用该模板可创建虚拟网络、Web 应用、专用终结点和专用 DNS 区域。
- 选择或创建资源组。
- 输入 Web 应用、Azure 应用服务计划、专用终结点的名称。
- 阅读有关条款和条件的声明。 如果你同意,请选择“我同意上述条款和条件”>“购买” 。 部署可能需要几分钟才能完成。
清理资源
如果不再需要为专用终结点创建的资源,请删除资源组。 这会删除该专用终结点和所有相关资源。
若要删除资源组,请调用 Remove-AzResourceGroup
cmdlet:
Remove-AzResourceGroup -Name <your resource group name>
后续步骤
- 可以在 ARM 模板示例中找到 Azure 应用服务 Web 应用的更多 Azure 资源管理器模板。