将自定义域分配到 Web 应用
此示例脚本使用其相关资源,在应用服务中创建 Web 应用,并将 www.<yourdomain>
映射到它。
必要时,请使用 Azure PowerShell 指南中的说明安装 Azure PowerShell,并运行 Login-AzureRmAccount -EnvironmentName AzureChinaCloud
创建与 Azure 的连接。 此外,还需有权访问域注册机构的 DNS 配置页。
示例脚本
$fqdn="<Replace with your custom domain name>"
$webappname="mywebapp$(Get-Random)"
$location="China North"
# Create a resource group.
New-AzureRmResourceGroup -Name $webappname -Location $location
# Create an App Service plan in Free tier.
New-AzureRmAppServicePlan -Name $webappname -Location $location `
-ResourceGroupName $webappname -Tier Free
# Create a web app.
New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname `
-ResourceGroupName $webappname
Write-Host "Configure a CNAME record that maps $fqdn to $webappname.chinacloudsites.cn"
Read-Host "Press [Enter] key when ready ..."
# Before continuing, go to your DNS configuration UI for your custom domain and follow the
# instructions at https://docs.azure.cn/app-service/app-service-web-tutorial-custom-domain to configure a CNAME record for the
# hostname "www" and point it your web app's default domain name.
# Upgrade App Service plan to Shared tier (minimum required by custom domains)
Set-AzureRmAppServicePlan -Name $webappname -ResourceGroupName $webappname `
-Tier Shared
# Add a custom domain name to the web app.
Set-AzureRmWebApp -Name $webappname -ResourceGroupName $webappname `
-HostNames @($fqdn,"$webappname.chinacloudsites.cn")
清理部署
运行脚本示例后,可以使用以下命令删除资源组、Web 应用以及所有相关资源。
Remove-AzureRmResourceGroup -Name myResourceGroup -Force
脚本说明
此脚本使用以下命令。 表中的每条命令均链接到特定于命令的文档。
命令 | 说明 |
---|---|
New-AzureRmResourceGroup | 创建用于存储所有资源的资源组。 |
New-AzureRmAppServicePlan | 创建应用服务计划。 |
New-AzureRmWebApp | 创建 Web 应用。 |
Set-AzureRmAppServicePlan | 修改应用服务计划以更改其定价层。 |
Set-AzureRmWebApp | 修改 Web 应用的配置。 |
后续步骤
有关 Azure PowerShell 模块的详细信息,请参阅 Azure PowerShell 文档。
可以在 Azure PowerShell 示例中找到 Azure 应用服务 Web 应用的其他 Azure Powershell 示例。