基于ARM模板通过MSDeploy/ZipDeploy部署Azure Web App至子应用求助
问题描述
通过ARM模板将应用部署至Azure Web App的虚拟应用时,尝试了多种IIS Web Application Name参数值([parameters('appName')]/subapp1、/subapp1、subapp1、Default Web Site/subapp1),并使用MSDeploy、addOnPackages、ZipDeploy三种扩展,文件始终部署到Web应用根目录,而非指定的虚拟应用路径。
解决方案
1. 修正MSDeploy扩展配置
针对Azure Web App虚拟应用部署,需调整MSDeploy的两个关键参数:
- 添加
skipAppCreation: true,避免MSDeploy重复创建IIS应用(虚拟应用已在Web App的siteConfig中定义) - 将
IIS Web Application Name设为Default Web Site/subapp1,匹配虚拟应用的IIS层级结构
修改后的MSDeploy扩展片段:
{ "type": "Microsoft.Web/sites/extensions", "apiVersion": "2022-03-01", "name": "[concat(parameters('appName'), '/MSDeploy')]", "dependsOn": [ "[resourceId('Microsoft.Web/sites', parameters('appName'))]" ], "properties": { "packageUri": "[uri(concat(parameters('_artifactsLocation'),'filesApp.zip'),parameters('_artifactsLocationSasToken'))]", "dbType": "None", "connectionString": "", "appOffline": true, "skipAppCreation": true, "setParameters": { "IIS Web Application Name": "Default Web Site/subapp1" } } }
2. 改用ZipDeploy扩展(更简便)
通过添加应用设置WEBSITE_ZIP_DEPLOYMENT_TARGET_PATH,直接指定ZipDeploy的目标物理路径:
步骤1:在Web App配置中添加应用设置
在siteConfig.appSettings中加入:
"appSettings": [ { "name": "WEBSITE_ZIP_DEPLOYMENT_TARGET_PATH", "value": "site\\wwwroot\\subapp1" } ]
步骤2:添加ZipDeploy扩展资源
{ "type": "Microsoft.Web/sites/extensions", "apiVersion": "2022-03-01", "name": "[concat(parameters('appName'), '/ZipDeploy')]", "dependsOn": [ "[resourceId('Microsoft.Web/sites', parameters('appName'))]" ], "properties": { "packageUri": "[uri(concat(parameters('_artifactsLocation'),'filesApp.zip'),parameters('_artifactsLocationSasToken'))]" } }
3. 完整修正后的ARM模板
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "type": "string", "metadata": { "description": "Location of resources" }, "defaultValue": "[resourceGroup().location]" }, "_artifactsLocation": { "type": "string", "metadata": { "description": "The base URI where artifacts required by this template are located including a trailing '/'" }, "defaultValue": "[deployment().properties.templateLink.uri]" }, "_artifactsLocationSasToken": { "type": "securestring", "metadata": { "description": "The sasToken required to access _artifactsLocation. When the template is deployed using the accompanying scripts, a sasToken will be automatically generated. Use the defaultValue if the staging location is not secured." }, "defaultValue": "" }, "appName": { "type": "string", "metadata": { "description": "App Name" }, "defaultValue": "testapp123" } }, "variables": { "existingPlanAppServiceName": "[concat('PlanAppService-',uniqueString(resourceGroup().id))]" }, "resources": [ { "apiVersion": "2022-03-01", "name": "[variables('existingPlanAppServiceName')]", "type": "Microsoft.Web/serverfarms", "location": "[parameters('location')]", "tags": {}, "dependsOn": [], "properties": { "name": "[variables('existingPlanAppServiceName')]", "workerSize": "18", "workerSizeId": "18", "numberOfWorkers": "1", "zoneRedundant": false }, "sku": { "Tier": "Premium0V3", "Name": "P0V3" } }, { "apiVersion": "2022-03-01", "name": "[parameters('appName')]", "type": "Microsoft.Web/sites", "location": "[parameters('location')]", "tags": {}, "dependsOn": [ "[resourceId('Microsoft.Web/serverfarms', variables('existingPlanAppServiceName'))]" ], "properties": { "name": "[parameters('appName')]", "siteConfig": { "metadata": [ { "name": "CURRENT_STACK", "value": "dotnet" } ], "virtualApplications": [ { "virtualPath": "/", "physicalPath": "site\\wwwroot", "preloadEnabled": false }, { "virtualPath": "/subapp1", "physicalPath": "site\\wwwroot\\subapp1", "preloadEnabled": true } ], "phpVersion": "OFF", "netFrameworkVersion": "v4.0", "alwaysOn": true, "ftpsState": "Disabled", "use32BitWorkerProcess": false, "http20Enabled": true, "websiteTimeZone": "SA Pacific Standard Time", "appSettings": [ { "name": "WEBSITE_ZIP_DEPLOYMENT_TARGET_PATH", "value": "site\\wwwroot\\subapp1" } ] }, "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('existingPlanAppServiceName'))]", "clientAffinityEnabled": false, "httpsOnly": true, "publicNetworkAccess": "Enabled" }, "resources": [ // 可选MSDeploy方式 { "type": "Microsoft.Web/sites/extensions", "apiVersion": "2022-03-01", "name": "[concat(parameters('appName'), '/MSDeploy')]", "dependsOn": [ "[resourceId('Microsoft.Web/sites', parameters('appName'))]" ], "properties": { "packageUri": "[uri(concat(parameters('_artifactsLocation'),'filesApp.zip'),parameters('_artifactsLocationSasToken'))]", "dbType": "None", "connectionString": "", "appOffline": true, "skipAppCreation": true, "setParameters": { "IIS Web Application Name": "Default Web Site/subapp1" } } }, // 可选ZipDeploy方式 { "type": "Microsoft.Web/sites/extensions", "apiVersion": "2022-03-01", "name": "[concat(parameters('appName'), '/ZipDeploy')]", "dependsOn": [ "[resourceId('Microsoft.Web/sites', parameters('appName'))]" ], "properties": { "packageUri": "[uri(concat(parameters('_artifactsLocation'),'filesApp.zip'),parameters('_artifactsLocationSasToken'))]" } } ] } ] }
验证步骤
部署完成后,可通过两种方式确认:
- 登录Azure门户,进入Web App的配置->虚拟应用和目录,确认
/subapp1的物理路径正确 - 访问Kudu工具(
https://<app-name>.scm.azurewebsites.net),查看site\wwwroot\subapp1目录是否存在部署文件
内容的提问来源于stack exchange,提问作者Frank Leao
相关产品推荐
相关产品推荐

