Szybki przewodnik: Jak utworzyć Front Door za pomocą Bicep

Ten przewodnik szybkiego startu przeprowadzi Cię przez proces tworzenia usługi Azure Front Door z aplikacją internetową jako źródło, korzystając z Bicep.

Uwaga

W przypadku obciążeń internetowych zdecydowanie zalecamy użycie usługi Azure DDoS Protection i zapory aplikacji internetowej w celu ochrony przed pojawiającymi się atakami DDoS. Inną opcją jest zastosowanie usługi Azure Front Door wraz z zaporą aplikacji internetowej. Usługa Azure Front Door oferuje ochronę na poziomie platformy przed atakami DDoS na poziomie sieci. Aby uzyskać więcej informacji, zobacz Punkt odniesienia zabezpieczeń dla usług platformy Azure.

Bicep to język specyficzny dla domeny (DSL), który używa składni deklaratywnej do wdrażania zasobów platformy Azure. Zapewnia zwięzłą składnię, niezawodne bezpieczeństwo typów i obsługę ponownego użycia kodu. Bicep oferuje najlepsze środowisko tworzenia rozwiązań infrastruktury jako kodu na platformie Azure.

Wymagania wstępne

  • Aktywna subskrypcja platformy Azure. Utwórz bezpłatne konto, jeśli go nie masz.
  • Adres IP lub nazwa FQDN witryny internetowej lub aplikacji internetowej.

Przejrzyj plik Bicep

Plik Bicep używany w tym przewodniku wprowadzającym jest dostępny w Azure Quickstart Templates.

W tym przewodniku szybkiego startu utworzysz profil Azure Front Door, usługę Azure App Service i skonfigurujesz usługę aplikacji, aby sprawdzić, czy ruch pochodzi od źródła Azure Front Door.

@description('The location into which regionally scoped resources should be deployed. Note that Front Door is a global resource.')
param location string = resourceGroup().location

@description('The name of the App Service application to create. This must be globally unique.')
param appName string = 'myapp-${uniqueString(resourceGroup().id)}'

@description('The name of the SKU to use when creating the App Service plan.')
param appServicePlanSkuName string = 'S1'

@description('The number of worker instances of your App Service plan that should be provisioned.')
param appServicePlanCapacity int = 1

@description('The name of the Front Door endpoint to create. This must be globally unique.')
param frontDoorEndpointName string = 'afd-${uniqueString(resourceGroup().id)}'

@description('The name of the SKU to use when creating the Front Door profile.')
@allowed([
  'Standard_AzureFrontDoor'
  'Premium_AzureFrontDoor'
])
param frontDoorSkuName string = 'Standard_AzureFrontDoor'

var appServicePlanName = 'AppServicePlan'

var frontDoorProfileName = 'MyFrontDoor'
var frontDoorOriginGroupName = 'MyOriginGroup'
var frontDoorOriginName = 'MyAppServiceOrigin'
var frontDoorRouteName = 'MyRoute'

resource frontDoorProfile 'Microsoft.Cdn/profiles@2021-06-01' = {
  name: frontDoorProfileName
  location: 'global'
  sku: {
    name: frontDoorSkuName
  }
}

resource appServicePlan 'Microsoft.Web/serverFarms@2020-06-01' = {
  name: appServicePlanName
  location: location
  sku: {
    name: appServicePlanSkuName
    capacity: appServicePlanCapacity
  }
  kind: 'app'
}

resource app 'Microsoft.Web/sites@2020-06-01' = {
  name: appName
  location: location
  kind: 'app'
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    serverFarmId: appServicePlan.id
    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': [
              frontDoorProfile.properties.frontDoorId
            ]
          }
          name: 'Allow traffic from Front Door'
        }
      ]
    }
  }
}

resource frontDoorEndpoint 'Microsoft.Cdn/profiles/afdEndpoints@2021-06-01' = {
  name: frontDoorEndpointName
  parent: frontDoorProfile
  location: 'global'
  properties: {
    enabledState: 'Enabled'
  }
}

resource frontDoorOriginGroup 'Microsoft.Cdn/profiles/originGroups@2021-06-01' = {
  name: frontDoorOriginGroupName
  parent: frontDoorProfile
  properties: {
    loadBalancingSettings: {
      sampleSize: 4
      successfulSamplesRequired: 3
    }
    healthProbeSettings: {
      probePath: '/'
      probeRequestType: 'HEAD'
      probeProtocol: 'Http'
      probeIntervalInSeconds: 100
    }
  }
}

resource frontDoorOrigin 'Microsoft.Cdn/profiles/originGroups/origins@2021-06-01' = {
  name: frontDoorOriginName
  parent: frontDoorOriginGroup
  properties: {
    hostName: app.properties.defaultHostName
    httpPort: 80
    httpsPort: 443
    originHostHeader: app.properties.defaultHostName
    priority: 1
    weight: 1000
  }
}

resource frontDoorRoute 'Microsoft.Cdn/profiles/afdEndpoints/routes@2021-06-01' = {
  name: frontDoorRouteName
  parent: frontDoorEndpoint
  dependsOn: [
    frontDoorOrigin // This explicit dependency is required to ensure that the origin group is not empty when the route is created.
  ]
  properties: {
    originGroup: {
      id: frontDoorOriginGroup.id
    }
    supportedProtocols: [
      'Http'
      'Https'
    ]
    patternsToMatch: [
      '/*'
    ]
    forwardingProtocol: 'HttpsOnly'
    linkToDefaultDomain: 'Enabled'
    httpsRedirect: 'Enabled'
  }
}

output appServiceHostName string = app.properties.defaultHostName
output frontDoorEndpointHostName string = frontDoorEndpoint.properties.hostName

Plik Bicep definiuje wiele zasobów platformy Azure:

Wdróż plik Bicep

  1. Zapisz plik Bicep jako main.bicep na komputerze lokalnym.

  2. Wdróż plik Bicep przy użyciu interfejsu wiersza polecenia platformy Azure lub programu Azure PowerShell.

    az group create --name exampleRG --location eastus
    az deployment group create --resource-group exampleRG --template-file main.bicep
    

    Po zakończeniu wdrażania powinny zostać wyświetlone dane wyjściowe podobne do następujących:

    Dane wyjściowe wdrożenia Front Door Bicep w programie PowerShell - zrzut ekranu.

Weryfikowanie wdrożenia

Użyj interfejsu wiersza polecenia platformy Azure lub programu Azure PowerShell, aby wyświetlić listę zasobów wdrożonych w grupie zasobów.

az resource list --resource-group exampleRG

Możesz również zweryfikować wdrożenie przy użyciu witryny Azure Portal.

  1. Zaloguj się w witrynie Azure Portal.

  2. Wybierz pozycję Grupy zasobów w okienku po lewej stronie.

  3. Wybierz grupę zasobów utworzoną w poprzedniej sekcji.

  4. Wybierz utworzony Front Door. Zostanie wyświetlona nazwa hosta punktu końcowego. Skopiuj nazwę hosta i wklej ją na pasku adresu przeglądarki. Naciśnij Enter, a żądania będą kierowane do aplikacji internetowej.

    Zrzut ekranu przedstawiający komunikat: Aplikacja internetowa jest uruchomiona i czeka na zawartość.

Czyszczenie zasobów

Gdy nie będą już potrzebne, użyj portalu Azure, Azure CLI lub Azure PowerShell, aby usunąć usługę Front Door i grupę zasobów. Usługa Front Door i wszystkie powiązane zasoby zostaną usunięte.

az group delete --name exampleRG

Następne kroki

W tym przewodniku Szybki Start utworzono:

  • Front Door
  • Plan Usługi aplikacji
  • Aplikacja internetowa

Aby dowiedzieć się, jak dodać domenę niestandardową do usługi Front Door, przejdź do samouczków usługi Front Door.