Egyéni tartomány hozzárendelése webalkalmazáshoz a PowerShell használatával

Ez a példaszkript egy webalkalmazást hoz létre az App Service szolgáltatásban a kapcsolódó erőforrásokkal együtt, majd leképezi rá a www.<yourdomain> tartományt.

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 hozzáféréssel kell rendelkeznie a tartományregisztrálója DNS-konfigurációs oldalához.

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>"
$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 Shared tier (minimum required by custom domains)
Set-AzAppServicePlan -Name $webappname -ResourceGroupName $webappname `
-Tier Shared

# Add a custom domain name to the web app. 
Set-AzWebApp -Name $webappname -ResourceGroupName $webappname `
-HostNames @($fqdn,"$webappname.azurewebsites.net")

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.

Következő lépések

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

A Azure App Service Web Apps további Azure PowerShell mintái a Azure PowerShell mintákban találhatók.