首页 > 解决方案 > 使用应用服务证书的 Azure ARM SSL 绑定

问题描述

我有一个在 ARM 模板中使用 hostnameBindings 配置的自定义主机名的站点。这部署得很好。

我还从 Azure 创建并验证了 SSL 证书,并带有相应的指纹。

在 Azure 站点中,我还可以将证书绑定到应用服务。

但是,当我使用 ARM 模板从 hostnameBindings 中的模板分配 SSL 时,它会给出一个错误,即找不到证书...

我不明白出了什么问题...

我的猜测:

在 hostnameBindings 我只定义指纹和 sslState

知道我错过了哪一步吗?

谢谢你

更新

我的参数json文件:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.5.0.8",
"parameters": {
    "baseResourceName": {
        "value": "base-name"
    },
    "environments": {
        "value": [
            "preview"
        ]
    },
    "hostNames": {
        "value": [
            {
                "name": "myhostname.example.com",
                "sslState": "SniEnabled",
                "thumbprint": "9897LKJL88KHKJH8888KLJLJLJLKJLJLKL4545"
            },
            {
                "name": "myhostname2.example.com"
            }              
        ]
    }, 
    "ipSecurityRestrictions": {
        "value": []
    }
}

}

我的模板 json 文件:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.5.0.8",
    "parameters": {
        "hostName": {
            "defaultValue": [],
            "type": "array",
            "metadata": {
                "description": "The custom hostnames of sites"
            }
        }
    },
    "variables": {
        "standardPlanMaxAdditionalSlots": 4,
        "appName": "[concat(parameters('baseResourceName'), '-private')]",
        "appServicePlanName": "[concat(parameters('baseResourceName'), '-appServicePlan')]",
        "appInsightName": "[concat(parameters('baseResourceName'), '-appInsight')]",
        "ipSecurityRestrictions": "[parameters('ipSecurityRestrictions')]"
    },
    "resources": [
        {
            "type": "Microsoft.Web/serverfarms",
            "comments": "AppPlan for app.",
            "sku": {
                "name": "[if(lessOrEquals(length(parameters('environments')), variables('standardPlanMaxAdditionalSlots')), 'S1', 'P1')]"
            },
            "tags": {
                "displayName": "AppServicePlan-Private"
            },
            "name": "[variables('appServicePlanName')]",
            "kind": "app",
            "apiVersion": "2016-09-01",
            "location": "[resourceGroup().location]",
            "properties": {},
            "dependsOn": []
        },
        {
            "type": "Microsoft.Web/sites",
            "comments": "This is the private web app.",
            "kind": "app",
            "apiVersion": "2016-03-01",
            "name": "[variables('appName')]",
            "location": "[resourceGroup().location]",
            "tags": {
                "displayName": "WebApp"
            },
            "properties": {
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
                "siteConfig": {
                    "appSettings": [],
                    "phpVersion": "",
                    "ipSecurityRestrictions": "[variables('ipSecurityRestrictions')]",
                    "http20Enabled": true,
                    "minTlsVersion": "1.2"
                }
            },
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
                "[resourceId('microsoft.insights/components/', variables('appInsightName'))]"
            ]
        },
        {
            "type": "Microsoft.Web/sites/hostnameBindings",
            "name": "[concat(variables('appName'), '/', parameters('hostName')[copyIndex()].Name)]",
            "apiVersion": "2016-03-01",
            "location": "[resourceGroup().location]",
            "properties": "[parameters('hostName')[copyIndex()]]",
            "condition": "[greater(length(parameters('hostName')), 0)]",
            "copy": {
                "name": "hostnameCopy",
                "count": "[length(parameters('hostName'))]",
                "mode": "Serial"
            },
            "dependsOn": [
                "[concat('Microsoft.Web/sites/',variables('appName'))]"
            ]
        }
    ]
}

标签: azuresslazure-resource-manager

解决方案


greater(..., 0)完全不相关,您是否使用零长度数组测试了您的条件?很确定它会爆炸。

就此主题而言。如果您将证书资源链接到应用服务计划,我认为您可能会使其工作。所以这是对证书资源执行的操作。如果您使用 keyvault 存储证书,这是完全可能的

    {
        "apiVersion": "2016-03-01",
        "name": "[variables('certificateName')]",
        "location": "[resourceGroup().location]",
        "type": "Microsoft.Web/certificates",
        "dependsOn": [
            "[parameters('appServicePlan')]"
        ],
        "properties": {
            "keyVaultId": "kvResourceId",
            "keyVaultSecretName": "secretName",
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlan'))]"
        }
    }

推荐阅读