التشغيل السريع: إنشاء Front Door Standard/Premium باستخدام قالب ARM

يصف هذا التشغيل السريع كيفية استخدام قالب Azure Resource Manager (قالب ARM) لإنشاء Azure Front Door Standard/Premium باستخدام تطبيق ويب كأصل.

قالب Azure Resource Manager هو ملف JavaScript Object Notation (JSON) الذي يحدد البنية الأساسية والتكوين لمشروعك. يستخدم القالب عبارات توضيحية. يمكنك وصف النشر المقصود دون كتابة تسلسل أوامر البرمجة لإنشاء النشر.

إذا كانت بيئتك تلبي المتطلبات الأساسية وكنت معتاداً على استخدام قوالب "ARM"، فحدد زر "Deploy to Azure". سيتم فتح القالب في مدخل Azure.

Button to deploy the Resource Manager template to Azure.

المتطلبات الأساسية

  • في حال لم يكن لديك اشتراك Azure، فأنشئ حساباً مجانيّاً قبل البدء.
  • IP أو FQDN لموقع ويب أو تطبيق ويب.

مراجعة القالب

يُعدّ النموذج المستخدم في هذا التشغيل السريع مأخوذاً من قوالب التشغيل السريع من Azure.

في هذا التشغيل السريع، ستقوم بإنشاء Front Door Standard/Premium، وخدمة التطبيقات، وتكوين App Service للتحقق من أن نسبة استخدام الشبكة قد جاءت من خلال أصل Front Door.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.5.6.12127",
      "templateHash": "1359495056007144414"
    }
  },
  "parameters": {
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "The location into which regionally scoped resources should be deployed. Note that Front Door is a global resource."
      }
    },
    "appName": {
      "type": "string",
      "defaultValue": "[format('myapp-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "The name of the App Service application to create. This must be globally unique."
      }
    },
    "appServicePlanSkuName": {
      "type": "string",
      "defaultValue": "S1",
      "metadata": {
        "description": "The name of the SKU to use when creating the App Service plan."
      }
    },
    "appServicePlanCapacity": {
      "type": "int",
      "defaultValue": 1,
      "metadata": {
        "description": "The number of worker instances of your App Service plan that should be provisioned."
      }
    },
    "frontDoorEndpointName": {
      "type": "string",
      "defaultValue": "[format('afd-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "The name of the Front Door endpoint to create. This must be globally unique."
      }
    },
    "frontDoorSkuName": {
      "type": "string",
      "defaultValue": "Standard_AzureFrontDoor",
      "allowedValues": [
        "Standard_AzureFrontDoor",
        "Premium_AzureFrontDoor"
      ],
      "metadata": {
        "description": "The name of the SKU to use when creating the Front Door profile."
      }
    }
  },
  "variables": {
    "appServicePlanName": "AppServicePlan",
    "frontDoorProfileName": "MyFrontDoor",
    "frontDoorOriginGroupName": "MyOriginGroup",
    "frontDoorOriginName": "MyAppServiceOrigin",
    "frontDoorRouteName": "MyRoute"
  },
  "resources": [
    {
      "type": "Microsoft.Cdn/profiles",
      "apiVersion": "2021-06-01",
      "name": "[variables('frontDoorProfileName')]",
      "location": "global",
      "sku": {
        "name": "[parameters('frontDoorSkuName')]"
      }
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2020-06-01",
      "name": "[variables('appServicePlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('appServicePlanSkuName')]",
        "capacity": "[parameters('appServicePlanCapacity')]"
      },
      "kind": "app"
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2020-06-01",
      "name": "[parameters('appName')]",
      "location": "[parameters('location')]",
      "kind": "app",
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
        "httpsOnly": true,
        "siteConfig": {
          "detailedErrorLoggingEnabled": true,
          "httpLoggingEnabled": true,
          "requestTracingEnabled": true,
          "ftpsState": "Disabled",
          "minTlsVersion": "1.2",
          "ipSecurityRestrictions": [
            {
              "tag": "ServiceTag",
              "ipAddress": "AzureFrontDoor.Backend",
              "action": "Allow",
              "priority": 100,
              "headers": {
                "x-azure-fdid": [
                  "[reference(resourceId('Microsoft.Cdn/profiles', variables('frontDoorProfileName'))).frontDoorId]"
                ]
              },
              "name": "Allow traffic from Front Door"
            }
          ]
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
        "[resourceId('Microsoft.Cdn/profiles', variables('frontDoorProfileName'))]"
      ]
    },
    {
      "type": "Microsoft.Cdn/profiles/afdEndpoints",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}', variables('frontDoorProfileName'), parameters('frontDoorEndpointName'))]",
      "location": "global",
      "properties": {
        "enabledState": "Enabled"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles', variables('frontDoorProfileName'))]"
      ]
    },
    {
      "type": "Microsoft.Cdn/profiles/originGroups",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}', variables('frontDoorProfileName'), variables('frontDoorOriginGroupName'))]",
      "properties": {
        "loadBalancingSettings": {
          "sampleSize": 4,
          "successfulSamplesRequired": 3
        },
        "healthProbeSettings": {
          "probePath": "/",
          "probeRequestType": "HEAD",
          "probeProtocol": "Http",
          "probeIntervalInSeconds": 100
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles', variables('frontDoorProfileName'))]"
      ]
    },
    {
      "type": "Microsoft.Cdn/profiles/originGroups/origins",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}/{2}', variables('frontDoorProfileName'), variables('frontDoorOriginGroupName'), variables('frontDoorOriginName'))]",
      "properties": {
        "hostName": "[reference(resourceId('Microsoft.Web/sites', parameters('appName'))).defaultHostName]",
        "httpPort": 80,
        "httpsPort": 443,
        "originHostHeader": "[reference(resourceId('Microsoft.Web/sites', parameters('appName'))).defaultHostName]",
        "priority": 1,
        "weight": 1000
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('appName'))]",
        "[resourceId('Microsoft.Cdn/profiles/originGroups', variables('frontDoorProfileName'), variables('frontDoorOriginGroupName'))]"
      ]
    },
    {
      "type": "Microsoft.Cdn/profiles/afdEndpoints/routes",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}/{2}', variables('frontDoorProfileName'), parameters('frontDoorEndpointName'), variables('frontDoorRouteName'))]",
      "properties": {
        "originGroup": {
          "id": "[resourceId('Microsoft.Cdn/profiles/originGroups', variables('frontDoorProfileName'), variables('frontDoorOriginGroupName'))]"
        },
        "supportedProtocols": [
          "Http",
          "Https"
        ],
        "patternsToMatch": [
          "/*"
        ],
        "forwardingProtocol": "HttpsOnly",
        "linkToDefaultDomain": "Enabled",
        "httpsRedirect": "Enabled"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles/afdEndpoints', variables('frontDoorProfileName'), parameters('frontDoorEndpointName'))]",
        "[resourceId('Microsoft.Cdn/profiles/originGroups/origins', variables('frontDoorProfileName'), variables('frontDoorOriginGroupName'), variables('frontDoorOriginName'))]",
        "[resourceId('Microsoft.Cdn/profiles/originGroups', variables('frontDoorProfileName'), variables('frontDoorOriginGroupName'))]"
      ]
    }
  ],
  "outputs": {
    "appServiceHostName": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Web/sites', parameters('appName'))).defaultHostName]"
    },
    "frontDoorEndpointHostName": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Cdn/profiles/afdEndpoints', variables('frontDoorProfileName'), parameters('frontDoorEndpointName'))).hostName]"
    }
  }
}

موارد Azure المتعددة مُعرَّفة في القالب:

نشر القالب

  1. حدِّد جربه من مكوِّن التعليمات البرمجية التالي لفتح Azure Cloud Shell، ثم اتبع الإرشادات لتسجيل الدخول إلى Azure.

    إشعار

    إذا كنت ترغب في نشر Azure Front Door Premium بدلًا من Standard، فاستبدل قيمة معلمة sku ب Premium_AzureFrontDoor. للمقارنة التفصيلية، راجع مقارنة مستوى Azure Front Door.

    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location (i.e. centralus)"
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.cdn/front-door-standard-premium-app-service-public/azuredeploy.json"
    
    $resourceGroupName = "${projectName}rg"
    
    New-AzResourceGroup -Name $resourceGroupName -Location "$location"
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -frontDoorSkuName Standard_AzureFrontDoor
    
    Read-Host -Prompt "Press [ENTER] to continue ..."
    

    انتظر حتى ترى المطالبة من وحدة التحكم.

  2. حدد النسخ من مكوِّن التعليمات البرمجية السابق لنسخ نص PowerShell.

  3. انقر بزر الماوس الأيمن على جزء وحدة تحكم shell، ثم حدِّد لصق.

  4. أدخل القيم.

    ينشئ نشر القالب واجهة أمامية باستخدام واجهة خلفية واحدة.

    اسم مجموعة الموارد هو اسم المشروع مع إلحاق rg.

    إشعار

    يجب أن يكون frontDoorName اسما فريدا عالميا حتى يتم نشر القالب بنجاح. إذا فشل النشر، فابدأ من جديد بالخطوة 1.

    يستغرق نشر القالب دقائق قليلة. عند الانتهاء، يكون الناتج مشابهاً لما يلي:

    Front Door Resource Manager template PowerShell deployment output

يستخدم Azure PowerShell لتوزيع القالب. بالإضافة إلى Azure PowerShell، يمكنك أيضاً استخدام مدخل Microsoft Azure وAzure CLI وواجهة برمجة تطبيقات REST. لمعرفة طرق النشر الأخرى، راجع نشر القوالب.

التحقُّق من صحة عملية النشر

  1. قم بتسجيل الدخول إلى بوابة Azure.

  2. حدد مجموعات الموارد من الجزء الأيسر.

  3. حدد مجموعة الموارد التي قمت بإنشائها في القسم السابق. الاسم الافتراضي لمجموعة الموارد هو اسم المشروع مع إلحاق rg.

  4. حدد Front Door الذي أنشأته وستتمكن من رؤية اسم مضيف نقطة النهاية. انسخ اسم المضيف والصقه على شريط العناوين في المستعرض. اضغط على مفتاح الإدخال وسيتم توجيه طلبك تلقائيًا إلى تطبيق الويب.

    Screenshot of the message: Your web app is running and waiting for your content.

تنظيف الموارد

عندما لم تعد بحاجة إلى خدمة Front Door، احذف مجموعة الموارد. هذا يزيل الواجهة الأمامية وجميع الموارد ذات الصلة.

لحذف مجموعة الموارد، اتصل بـ Remove-AzResourceGroup cmdlet:

Remove-AzResourceGroup -Name <your resource group name>

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

في هذه البداية السريعة، قمت بإنشاء:

  • Front Door
  • خطة App Service
  • تطبيق الويب

لمعرفة كيفية إضافة مجال مخصص إلى الواجهة الأمامية الخاصة بك، تابع إلى البرامج التعليمية الخاصة بالواجهة الأمامية.