Baca dalam bahasa Inggris

Bagikan melalui


Mulai Cepat: Membuat Front Door menggunakan Bicep

Mulai cepat ini memandu Anda menggunakan Bicep untuk membuat Azure Front Door dengan Aplikasi Web sebagai asal.

Catatan

Untuk beban kerja web, sebaiknya gunakan perlindungan Azure DDoS dan firewall aplikasi web untuk melindungi dari serangan DDoS yang muncul. Opsi lain adalah menggunakan Azure Front Door bersama dengan firewall aplikasi web. Azure Front Door menawarkan perlindungan tingkat platform terhadap serangan DDoS tingkat jaringan. Untuk informasi selengkapnya, lihat garis besar keamanan untuk layanan Azure.

Bicep adalah bahasa pemrogram khusus domain (DSL) yang menggunakan sintaks deklaratif untuk menyebarkan sumber daya Azure. Bicep menyediakan sintaks ringkas, keamanan jenis yang andal, dan dukungan untuk penggunaan kembali kode. Bicep menawarkan pengalaman penulisan terbaik untuk solusi infrastructure-as-code di Azure.

Prasyarat

  • Langganan Azure aktif. Buat akun gratis jika Anda tidak memilikinya.
  • Alamat IP atau FQDN situs web atau aplikasi web.

Tinjau file Bicep

File Bicep yang digunakan dalam mulai cepat ini tersedia dari Templat Mulai Cepat Azure.

Dalam mulai cepat ini, Anda akan membuat profil Azure Front Door, Azure App Service, dan mengonfigurasi layanan aplikasi untuk memvalidasi bahwa lalu lintas datang melalui asal Azure Front Door.

Bicep
@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

File Bicep menentukan beberapa sumber daya Azure:

Menerapkan file Bicep

  1. Simpan file Bicep sebagai main.bicep di komputer lokal Anda.

  2. Sebarkan file Bicep menggunakan Azure CLI atau Azure PowerShell.

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

    Setelah penyebaran selesai, Anda akan melihat output yang mirip dengan:

    Cuplikan layar dari output penyebaran PowerShell Bicep Front Door.

Memvalidasi penyebaran

Gunakan Azure CLI atau Azure PowerShell untuk mencantumkan sumber daya yang disebarkan dalam grup sumber daya.

Azure CLI
az resource list --resource-group exampleRG

Anda juga dapat memvalidasi penyebaran menggunakan portal Azure.

  1. Masuk ke portal Azure.

  2. Pilih Grup sumber daya dari panel kiri.

  3. Pilih grup sumber daya yang Anda buat di bagian sebelumnya.

  4. Pilih Front Door yang Anda buat. Anda akan melihat nama host titik akhir. Salin nama host dan tempelkan ke bilah alamat browser. Tekan enter, dan permintaan Anda akan dirutekan ke aplikasi web.

    Cuplikan layar pesan: Aplikasi web Anda sedang berjalan dan menunggu konten.

Membersihkan sumber daya

Saat tidak lagi diperlukan, gunakan portal Azure, Azure CLI, atau Azure PowerShell untuk menghapus layanan Front Door dan grup sumber daya. Front Door dan semua sumber daya terkait dihapus.

Azure CLI
az group delete --name exampleRG

Langkah berikutnya

Dalam mulai cepat ini, Anda membuat:

  • Front Door
  • Paket App Service
  • Aplikasi Web

Untuk mempelajari cara menambahkan domain kustom ke Front Door Anda, lanjutkan ke tutorial Front Door.