共用方式為


使用 Azure Resource Manager 範本建立 App Service 應用程式和部署私人端點

在本快速入門中,您將使用 Azure Resource Manager (ARM) 範本建立 Web 應用程式並與私人端點公開。

Azure Resource Manager 範本是一個 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 Resource Manager 範本部署至 Azure 的方法:

  1. 若要登入 Azure 並開啟範本,請選取此連結:部署至 Azure。 此範本會建立虛擬網路、Web 應用程式、私人端點和私人 DNS 區域。
  2. 選取或建立資源群組。
  3. 輸入 Web 應用程式的名稱、Azure App Service 方案和私人端點。
  4. 閱讀條款及條件聲明。 若同意,請選取 [我同意上方所述的條款及條件]>[購買]。 部署需要幾分鐘才能完成。

清除資源

當您不再需要先前為私人端點建立的資源時,請刪除資源群組。 這會移除私人端點和所有相關資源。

呼叫 Remove-AzResourceGroup Cmdlet 以刪除資源群組:

Remove-AzResourceGroup -Name <your resource group name>

下一步

  • 您可以在 ARM 範本範例中找到適用於 Azure App Service Web Apps 的其他 Azure Resource Manager 範本。