تحويل نطاق مخصص إلى تطبيق ويب باستخدام PowerShell

ينشئ هذا البرنامج النصي النموذجي تطبيق ويب في خدمة التطبيقات مع موارده ذات الصلة، ثم يقوم بتحويل الخرائط www.<yourdomain> له.

إذا لزم الأمر، فقم بتثبيت Azure PowerShell باستخدام الإرشادات المذكورة في دليل Azure PowerShell ، ثم قم بتشغيله Connect-AzAccount لإنشاء اتصال مع Azure. بالإضافة إلى ذلك، يجب الوصول إلى صفحة تكوين DNS لمجال المسجل الخاص بك.

نموذج البرنامج النصي

إشعار

نوصي باستخدام الوحدة النمطية Azure Az PowerShell للتفاعل مع Azure. راجع تثبيت Azure PowerShell للبدء. لمعرفة كيفية الترحيل إلى الوحدة النمطية Az PowerShell، راجع ترحيل Azure PowerShell من AzureRM إلى Az.

$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")

تنظيف النشر

بعد تشغيل نموذج البرنامج النصي، يمكن استخدام الأمر التالي لإزالة مجموعة الموارد وتطبيق الويب مع كافة الموارد المقترنة بها.

Remove-AzResourceGroup -Name myResourceGroup -Force

شرح السيناريو

يستخدم هذا البرنامج النصي الأوامر التالية. يرتبط كل أمر في الجدول بأمر وثائق معينة.

الأمر ملاحظات
New-AzResourceGroup إنشاء مجموعة موارد يتم تخزين كل الموارد فيها.
New-AzAppServicePlan ينشئ خطة خدمة التطبيق.
New-AzWebApp ينشئ تطبيق ويب.
Set-AzAppServicePlan تعديل خطة خدمة التطبيقات لتغيير مستوى التسعير الخاص بها.
Set-AzWebApp تعديل تكوين تطبيق ويب.

الخطوات التالية

لمزيد من المعلومات حول وحدةAzure PowerShell، يرجى الاطلاع على وثائق Azure PowerShell.

يمكن العثور على نماذج Azure PowerShell الإضافية لتطبيقات Azure App Service Web Apps في نماذج Azure PowerShell.