首先,在 ARM 模板中添加以下代码以禁用默认文档:
{
"type": "Microsoft.Web/sites/config",
"name": "[concat(parameters('appName'), '/web')]",
"apiVersion": "2020-06-01",
"properties": {
"defaultDocuments": [
{
"enabled": false,
"value": "index.html"
}
]
}
}
然后,为应用程序添加 index.html 文件或其他要显示的默认文档。
此外,您还可以在 ARM 模板中添加以下 PowerShell 脚本,以强制应用程序重新启动并使更改生效:
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-05-01",
"name": "[concat(parameters('appName'), '-restart')]",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('restartTemplateUri')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"appResourceId": {
"value": "[resourceId('Microsoft.Web/sites', parameters('appName'))]"
}
}
}
}
将此代码添加到 ARM 模板中的适当位置,并将变量'restartTemplateUri”设置为指向以下 PowerShell 脚本的 URL:
$PropertiesObject = @{
"commandToExecute" = "powershell -nop -c 'Restart-WebAppPool -Name DefaultAppPool; Restart-WebAppPool -Name DefaultAppPool;'";
}
$ResourceObject = @{
"type" = "Microsoft.Web/sites/config";
"name" = "web";
"apiVersion" = "2020-06-01";
"properties" = $PropertiesObject;
}
Set-AzResource -ResourceGroupName "MyResourceGroup" -ResourceType "Microsoft.Web/sites/config" -ResourceName "MyWebApp/web" -PropertyObject $ResourceObject -Force
此脚本使用 Az PowerShell 模块中的 Set-AzResource 命令强制应用程序重新启动。
上一篇:AzureAPIM策略过于庞大