クイックスタート: Bicep を使用して Front Door を作成する
このクイックスタートでは、Bicep を使って、Web アプリを配信元とする Azure Front Door を作成する方法について説明します。
Note
Web ワークロードの場合は、新たな DDoS 攻撃から保護するために Azure DDoS 保護と Web アプリケーション ファイアウォールを利用することを強くお勧めします。 もう 1 つのオプションは、Web アプリケーション ファイアウォールと共に Azure Front Door を使用することです。 Azure Front Door は、ネットワーク レベルの DDoS 攻撃に対するプラットフォーム レベルの保護を提供します。 詳細については、Azure サービスのセキュリティ ベースラインに関するページを参照してください。
Bicep は、宣言型の構文を使用して Azure リソースをデプロイするドメイン固有言語 (DSL) です。 簡潔な構文、信頼性の高いタイプ セーフ、およびコードの再利用のサポートが提供されます。 Bicep により、Azure のコード ソリューションとしてのインフラストラクチャに最適な作成エクスペリエンスが実現します。
前提条件
- Azure サブスクリプションをお持ちでない場合は、開始する前に 無料アカウント を作成してください。
- Web サイトまたはアプリケーションの IP または FQDN。
Bicep ファイルを確認する
このクイックスタートで使用される Bicep ファイルは、Azure クイックスタート テンプレートからのものです。
このクイック スタートでは、Azure Front Door プロファイルと Azure App Service を作成し、トラフィックが 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
Bicep ファイルには複数の Azure リソースが定義されています。
- Microsoft.Cdn/profiles (Azure Front Door Standard/Premium プロファイル)
- Microsoft.Web/serverfarms (Web アプリをホストするための App Service プラン)
- Microsoft.Web/sites (Front Door の Web アプリの配信元サービス要求)
Bicep ファイルをデプロイする
Bicep ファイルを main.bicep としてローカル コンピューターに保存します。
Azure CLI または Azure PowerShell のどちらかを使用して Bicep ファイルをデプロイします。
az group create --name exampleRG --location eastus az deployment group create --resource-group exampleRG --template-file main.bicep
デプロイが完了すると、出力は次のようになります。
デプロイの検証
Azure CLI または Azure PowerShell を使用して、リソース グループ内のデプロイ済みリソースを一覧表示します。
az resource list --resource-group exampleRG
Azure portal を使用してデプロイを検証することもできます。
Azure portal にサインインします。
左側のウィンドウから [リソース グループ] を選択します。
前のセクションで作成したリソース グループを選択します
作成した Front Door を選択すると、エンドポイントのホスト名が表示されます。 ホスト名をコピーし、ブラウザーのアドレス バーに貼り付けます。 Enter キーを押すと、要求が自動的に Web アプリにルーティングされます。
リソースをクリーンアップする
不要になったら、Azure portal、Azure CLI、Azure PowerShell のいずれかを使用して Front Door サービスとリソース グループを削除します。 Front Door とすべての関連リソースは削除されます。
az group delete --name exampleRG
次のステップ
このクイックスタートでは、次のものを作成しました。
- Front Door
- App Service プラン
- Web アプリ
フロント ドアにカスタム ドメインを追加する方法を学習するには、Front Door のチュートリアルに進んでください。