azure - 使用 Azure CLI 将 SSL 证书从 KeyVault 绑定(bind)到 webapp

标签 azure ssl azure-web-app-service azure-cli

我们目前正在使用以下 ARM 模板将 SSL 证书绑定(bind)到 WebApp,但我们想迁移到 Azure CLI,但无法在不下载证书的情况下找到执行此操作的方法。

{
  "type": "Microsoft.Web/certificates",
  "name": "[variables('certificateName')]",
  "apiVersion": "2016-03-01",
  "location": "[resourceGroup().location]",
  "properties": {
    "keyVaultId": "[resourceId(parameters('existingKeyVaultResourceGroup'), 'Microsoft.KeyVault/vaults',parameters('existingKeyVaultId'))]",
    "keyVaultSecretName": "[parameters('existingKeyVaultSecretName')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverFarms',variables('hostingPlanName'))]"
  }
},
{
  "type": "Microsoft.Web/sites/hostnameBindings",
  "name": "[concat(variables('webAppName'), '/', variables('hostname'))]",
  "apiVersion": "2016-03-01",
  "location": "[resourceGroup().location]",
  "properties": {
    "sslState": "SniEnabled",
    "thumbprint": "[reference(resourceId('Microsoft.Web/certificates', variables('certificateName'))).Thumbprint]"
  },
  "dependsOn": [
    "[concat('Microsoft.Web/certificates/',variables('certificateName'))]"
  ]
}

最佳答案

这是官方的示例脚本site ,如果你不想下载它,你应该在你的本地。

#!/bin/bash

fqdn=<replace-with-www.{yourdomain}>
pfxPath=<replace-with-path-to-your-.PFX-file>
pfxPassword=<replace-with-your=.PFX-password>
resourceGroup=myResourceGroup
webappname=mywebapp$RANDOM

# Create a resource group.
az group create --location westeurope --name $resourceGroup

# Create an App Service plan in Basic tier (minimum required by custom domains).
az appservice plan create --name $webappname --resource-group $resourceGroup --sku B1

# Create a web app.
az webapp create --name $webappname --resource-group $resourceGroup \
--plan $webappname

echo "Configure a CNAME record that maps $fqdn to $webappname.azurewebsites.net"
read -p "Press [Enter] key when ready ..."

# Before continuing, go to your DNS configuration UI for your custom domain and 
follow the 
# instructions at https://aka.ms/appservicecustomdns to configure a CNAME record for 
the 
# hostname "www" and point it your web app's default domain name.

# Map your prepared custom domain name to the web app.
az webapp config hostname add --webapp-name $webappname --resource-group 
$resourceGroup \
--hostname $fqdn

# Upload the SSL certificate and get the thumbprint.
thumbprint=$(az webapp config ssl upload --certificate-file $pfxPath \
--certificate-password $pfxPassword --name $webappname --resource-group 
$resourceGroup \
--query thumbprint --output tsv)

# Binds the uploaded SSL certificate to the web app.
az webapp config ssl bind --certificate-thumbprint $thumbprint --ssl-type SNI \
--name $webappname --resource-group $resourceGroup

echo "You can now browse to https://$fqdn"

希望对您有所帮助,如果您还有其他问题,请告诉我。

关于azure - 使用 Azure CLI 将 SSL 证书从 KeyVault 绑定(bind)到 webapp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54039467/

相关文章:

ssl - 如何使用 LDAP ApacheDS 配置 CAS 4.0

docker - 延迟 : Temporary AUTH failure with SMTP Relay over port 587

azure - 交换槽中的名称在 azure 中显示阶段和生产的相同名称

asp.net-mvc - 如何获取Azure Files文件的公共(public)URL?

azure - 如何使用 cloningInfo 创建 azure 插槽?

.net - 确定 Web 应用代码是否正在 Azure Web 角色中运行

Azure Portal添加可以创建Web应用程序,sql服务器和其他资源的用户

Python - SSL 客户端/服务器证书

azure - Power BI Embedded 中的安全筛选

azure - 按标签名称查找 Azure 资源组