Примечание
Для доступа к этой странице требуется авторизация. Вы можете попробовать войти или изменить каталоги.
Для доступа к этой странице требуется авторизация. Вы можете попробовать изменить каталоги.
This sample script creates a web app in App Service with its related resources, then binds the TLS/SSL certificate of a custom domain name to it.
При необходимости установите Azure PowerShell с помощью инструкции, приведенной в руководстве Azure PowerShell, а затем выполните команду Connect-AzAccount
, чтобы создать подключение к Azure. Also, ensure that:
- A connection with Azure has been created using the
az login
command. - You have access to your domain registrar's DNS configuration page.
- You have a valid .PFX file and its password for the TLS/SSL certificate you want to upload and bind.
Пример скрипта
Примечание.
Мы рекомендуем использовать модуль Azure Az PowerShell для взаимодействия с Azure. Сведения о начале работы см. в статье "Установка Azure PowerShell". Чтобы узнать, как перейти на модуль Az PowerShell, см. статью Миграция Azure PowerShell с AzureRM на Az.
$fqdn="<Replace with your custom domain name>"
$pfxPath="<Replace with path to your .PFX file>"
$pfxPassword="<Replace with your .PFX password>"
$webappname="mywebapp$(Get-Random)"
$location="West Europe"
# Create a resource group.
New-AzResourceGroup -Name $webappname -Location $location
# Create an App Service plan in Free tier.
New-AzAppServicePlan -Name $webappname -Location $location `
-ResourceGroupName $webappname -Tier Free
# Create a web app.
$webapp = New-AzWebApp -Name $webappname -Location $location -AppServicePlan $webappname `
-ResourceGroupName $webappname
Write-Host "Sign in to your domain provider's website and configure the following records:"
Write-Host "A CNAME record that maps $fqdn to $webappname.azurewebsites.net"
Write-Host "A TXT record that maps asuid.$fqdn to the domain verification ID $($webapp.CustomDomainVerificationId)"
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://aka.ms/appservicecustomdns to configure a CNAME record for the
# hostname "www" and point it your web app's default domain name.
# Upgrade App Service plan to Basic tier (minimum required by custom SSL certificates)
Set-AzAppServicePlan -Name $webappname -ResourceGroupName $webappname `
-Tier Basic
# Add a custom domain name to the web app.
Set-AzWebApp -Name $webappname -ResourceGroupName $webappname `
-HostNames @($fqdn,"$webappname.azurewebsites.net")
# Upload and bind the SSL certificate to the web app.
New-AzWebAppSSLBinding -WebAppName $webappname -ResourceGroupName $webappname -Name $fqdn `
-CertificateFilePath $pfxPath -CertificatePassword $pfxPassword -SslState SniEnabled
Clean up deployment
After the script sample has been run, the following command can be used to remove the resource group, web app, and all related resources.
Remove-AzResourceGroup -Name myResourceGroup -Force
Объяснение скрипта
Этот скрипт использует следующие команды. Для каждой команды в таблице приведены ссылки на соответствующую документацию.
командование | Примечания. |
---|---|
New-AzResourceGroup | Создает группу ресурсов, в которой хранятся все ресурсы. |
New-AzAppServicePlan | Creates an App Service plan. |
New-AzWebApp | Creates a web app. |
Set-AzAppServicePlan | Modifies an App Service plan to change its pricing tier. |
Set-AzWebApp | Modifies a web app's configuration. |
New-AzWebAppSSLBinding | Creates a TLS/SSL certificate binding for a web app. |
Дальнейшие действия
Дополнительные сведения о модуле Azure PowerShell см. в документации по Azure PowerShell.
Additional Azure PowerShell samples for Azure App Service Web Apps can be found in the Azure PowerShell samples.