Egyéni TLS-/SSL-tanúsítvány kötése webalkalmazáshoz a PowerShell használatával

Ez a példaszkript létrehoz egy webalkalmazást App Service a kapcsolódó erőforrásokkal együtt, majd egy egyéni tartománynév TLS-/SSL-tanúsítványát köti hozzá.

Ha szükséges, telepítse a Azure PowerShell a Azure PowerShell útmutatóban található utasítással, majd futtassa a parancsot Connect-AzAccount az Azure-ral való kapcsolat létrehozásához. Emellett győződjön meg a következőkről is:

  • Ki lett építve kapcsolat az Azure-ral az az login parancs használatával.
  • Hozzáfér a tartományregisztrálója DNS-konfigurációs oldalához.
  • Érvényes . PFX-fájl és annak jelszava a feltölteni és kötni kívánt TLS/SSL-tanúsítványhoz.

Példaszkript

Megjegyzés

Javasoljuk, hogy az Azure Az PowerShell-modullal kommunikáljon az Azure-ral. Az első lépésekhez tekintse meg az Azure PowerShell telepítését ismertető szakaszt. Az Az PowerShell-modulra történő migrálás részleteiről lásd: Az Azure PowerShell migrálása az AzureRM modulból az Az modulba.

$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

Az üzemelő példány eltávolítása

A példaszkript futtatása után a következő paranccsal távolítható el az erőforráscsoport, a webalkalmazás és az összes kapcsolódó erőforrás.

Remove-AzResourceGroup -Name myResourceGroup -Force

Szkript ismertetése

A szkript a következő parancsokat használja. A táblázatban lévő összes parancs a hozzá tartozó dokumentációra hivatkozik.

Parancs Jegyzetek
New-AzResourceGroup Létrehoz egy erőforráscsoportot, amely az összes erőforrást tárolja.
New-AzAppServicePlan Létrehoz egy App Service-csomagot.
New-AzWebApp Webalkalmazást hoz létre.
Set-AzAppServicePlan Egy App Service-csomag tarifacsomagját módosítja.
Set-AzWebApp Módosítja egy webalkalmazás konfigurációját.
New-AzWebAppSSLBinding TLS-/SSL-tanúsítványkötést hoz létre egy webalkalmazáshoz.

Következő lépések

Az Azure PowerShell modullal kapcsolatos további információért lásd az Azure PowerShell dokumentációját.

További Azure Powershell-példákat az Azure App Service Web Appshez az Azure PowerShell-példák között találhat.