简体   繁体   English

Azure WebApp - 单个请求中的多个自定义域

[英]Azure WebApp - Multiple Custom Domains in single request

I'm trying to bulk upload custom domains to Azure WebApps (specifically the deployment slots).我正在尝试将自定义域批量上传到 Azure WebApps(特别是部署槽)。 I currently loop through with Azure CLI but it adds 15-20 minutes to CICD process.我目前使用 Azure CLI 循环,但它增加了 CICD 过程 15-20 分钟。

I've also tried with ARM Templates but it reports a "conflict" during bulk upload.我也尝试过使用 ARM 模板,但它在批量上传期间报告“冲突”。 It requires a condition or dependency on the previous hostname which means it's still configuring the domains one by one.它需要对先前主机名的条件或依赖,这意味着它仍在逐个配置域。

Does anyone know of a way to bulk configure?有谁知道批量配置的方法?

Powershell and Azure CLI Powershell 和 Azure CLI

#Set Host Names and SSL
  $WebApp_HostNames = Import-Csv "$(ConfigFiles_Path)\$WebApp-Hostnames.csv"
  if ($null -ne $WebApp_HostNames) {
    foreach ($HostName in $WebApp_HostNames) {
      az webapp config hostname add --hostname $HostName.Name --resource-group "$(ResourceGroup)" --webapp-name "$WebApp" --slot "$WebApp$(WebApp_Slot_Suffix)"
      az webapp config ssl bind --certificate-thumbprint $HostName.Thumbprint --ssl-type SNI --resource-group "$(ResourceGroup)" --name "$WebApp"  --slot "$WebApp$(WebApp_Slot_Suffix)"
    }
  }

EDIT : Got it!编辑:明白了! Will write out the process and provide the answer here for future reference将写出过程并在此处提供答案以供将来参考

TL;DR TL;博士

I've included the entire Powershell script here including getting your auth token and pushing the json config.我在这里包含了整个 Powershell 脚本,包括获取您的身份验证令牌和推送 json 配置。 There's nothing else you'll need to bulk upload.您无需批量上传其他任何内容。

Hope this helps希望这可以帮助

# Get auth token from existing Context
$currentAzureContext = Get-AzContext
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azProfile)
$token = $profileClient.AcquireAccessToken($currentAzureContext.Tenant.TenantId)

# Authorisation Header
$authHeader = @{
 'Content-Type'  = 'application/json'
 'Authorization' = 'Bearer ' + ($token.AccessToken)
}

# Request URL
$url = "https://management.azure.com/subscriptions/{SubscriptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Web/sites/{WebAppName}/slots/{WebAppSlotName}?api-version=2018-11-01"

# JSON body
$body = '
{
    "id":"/subscriptions/{SubscriptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Web/sites/{WebAppName}/slots/{WebAppSlotName}",
    "kind":"app",
    "location":"Australia East",
    "name":"{WebAppName} or {WebAppSlotName}",
    "type":"Microsoft.Web/sites/slots", or "Microsoft.Web/sites",
    "properties":{
        "hostNameSslStates":[
            {
                "name":"sub1.domain.com",
                "sslState":"SniEnabled",
                "thumbprint":"IUAHSIUHASD78ASDIUABFKASF79ASUASD8ASFHOANKSL",
                "toUpdate":true,
                "hostType":"Standard"
            
            },
            {
                "name":"sub2.domain.com",
                "sslState":"SniEnabled",
                "thumbprint":"FHISGF8A7SFG9SUGBSA7G9ASHIAOSHDF08ASHDF08AS",
                "toUpdate":true,
                "hostType":"Standard"
            
            }
        ],
        "hostNames":[
            "sub1.domain.com",
            "sub2.domain.com",
            "{Default WebApp Domain}"
        ]
    }
}
'

# Push to Azure
Invoke-RestMethod -Uri $url -Body $body -Method PUT -Headers $authHeader

Method方法

In the end I just pressed F12 to capture the traffic in the Networking tab in browser developer tools.最后,我只是按 F12 来捕获浏览器开发人员工具中 Networking 选项卡中的流量。

When clicking "Add Binding" in portal there's one PUT request which has the payload required to replicate.在门户中单击“添加绑定”时,会出现一个PUT请求,其中包含复制所需的有效负载。 I found that the request contains ALL of the Custom Domains and SSL bindings for bulk upload, not just the change.我发现该请求包含用于批量上传的所有自定义域和 SSL 绑定,而不仅仅是更改。 The only trick here was to set the toUpdate property to true for all domains.这里唯一的技巧是将所有域的toUpdate属性设置为true I stripped out any null and notConfigured values to keep it tidier.我删除了所有nullnotConfigured值以使其更整洁。

My next progression for this is to fetch my hostnames and certificate thumbprints and dynamically build the body before pushing the change to Azure.我的下一个进展是获取我的主机名和证书指纹并在将更改推送到 Azure 之前动态构建主体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有多个自定义域的Azure VM - Azure VM with multiple custom domains 具有多个自定义域的Azure网站应用程序 - Azure Web Site App with multiple custom domains 在 Azure 上使用通配符域时,如何防止某些自定义域访问您的 WebApp? - How to, while using wildcard domain on Azure, prevent some custom domains from accessing your WebApp? 如何配置Google域以指向Azure WebApp - How to configure google domains to point to Azure webapp 使单个Azure WebRole在单独的SSL证书上支持多个域 - Getting single Azure WebRole to support multiple domains on seperate SSL certificates 单个Azure B2C应用程序的多个域 - Multiple domains for single Azure B2C Application Azure中的自定义域和SSL - Custom domains and SSL in azure 优先考虑在单个 WebApp 中运行的多个 Azure Web 作业之一 - Give priority to one of multiple Azure WebJobs running in a single WebApp 使用自定义参数将多个域重定向到相同的Azure网站 - Redirect multiple domains to same azure website with custom parameters 如何将Azure上的多个自定义域映射到同一台服务器,但使用不同的URL? - How to map multiple custom domains on Azure to the same server, but different URL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM