Microsoft Azure の App Service の1つである Web Apps を使う場合、Web Apps が Application Gateway に対応してない問題があって、Web Application Proxy(WAF) を使う場合に、ちょっと工夫が必要でした。
例えば、
- App Service Enviroment を使うとか
How to run an App Service behind a WAF-enabled Application GatewayIntroductionYou may have heard of the Azure Application Gateway which is aLayer-7 HTTP load balancer that provides appli... - mod_security を使うとか
Microsoft Azure BlogAzure helps you build, run, and manage your applications. Get the latest news, updates, and announcements here from expe...
だけど、ついにApplication Gateway が Web Apps に対応したみたいです。
https://docs.microsoft.com/ja-jp/azure/application-gateway/application-gateway-web-app-overview
※ 2018/11/11 追記
Application Gateway の機能について、以下の記事で整理してみました。
ってことで試してみた
ひとまず、チュートリアルを見ながら作ってみました。
参考にしたドキュメント
https://docs.microsoft.com/ja-jp/azure/application-gateway/application-gateway-web-app-powershell
「新しいアプリケーション ゲートウェイの背後にある Web アプリケーションの構成」のあたりを参考に、Web Apps と Application Gateway を新規に作ってみました。
実行したPower Shell は、ドキュメントの内容と全く一緒ですが、一応乗っけときます。
ちなみに、実行する前にはAzure PowerShell を最新にUpdateしておきましょう。
あと、この PowerShell を実行する際には、先に、Login-AzureRmAccount をしています。
# Defines a variable for a dotnet get started web app repository location
$gitrepo="https://github.com/Azure-Samples/app-service-web-dotnet-get-started.git"
# Unique web app name
$webappname="mywebapp$(Get-Random)"
# Creates a resource group
$rg = New-AzureRmResourceGroup -Name (リソースグループ名) -Location Eastus
# Create an App Service plan in Free tier.
New-AzureRmAppServicePlan -Name $webappname -Location EastUs -ResourceGroupName $rg.ResourceGroupName -Tier Free
# Creates a web app
$webapp = New-AzureRmWebApp -ResourceGroupName $rg.ResourceGroupName -Name $webappname -Location EastUs -AppServicePlan $webappname
# Configure GitHub deployment from your GitHub repo and deploy once to web app.
$PropertiesObject = @{
repoUrl = "$gitrepo";
branch = "master";
isManualIntegration = "true";
}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $rg.ResourceGroupName -ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName $webappname/web -ApiVersion 2015-08-01 -Force
# Creates a subnet for the application gateway
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name subnet01 -AddressPrefix 10.0.0.0/24
# Creates a vnet for the application gateway
$vnet = New-AzureRmVirtualNetwork -Name appgwvnet -ResourceGroupName $rg.ResourceGroupName -Location EastUs -AddressPrefix 10.0.0.0/16 -Subnet $subnet
# Retrieve the subnet object for use later
$subnet=$vnet.Subnets[0]
# Create a public IP address
$publicip = New-AzureRmPublicIpAddress -ResourceGroupName $rg.ResourceGroupName -name publicIP01 -location EastUs -AllocationMethod Dynamic
# Create a new IP configuration
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration -Name gatewayIP01 -Subnet $subnet
# Create a backend pool with the hostname of the web app
$pool = New-AzureRmApplicationGatewayBackendAddressPool -Name appGatewayBackendPool -BackendIPAddresses $webapp.HostNames
# Define the status codes to match for the probe
$match = New-AzureRmApplicationGatewayProbeHealthResponseMatch -StatusCode 200-399
# Create a probe with the PickHostNameFromBackendHttpSettings switch for web apps
$probeconfig = New-AzureRmApplicationGatewayProbeConfig -name webappprobe -Protocol Http -Path / -Interval 30 -Timeout 120 -UnhealthyThreshold 3 -PickHostNameFromBackendHttpSettings -Match $match
# Define the backend http settings
$poolSetting = New-AzureRmApplicationGatewayBackendHttpSettings -Name appGatewayBackendHttpSettings -Port 80 -Protocol Http -CookieBasedAffinity Disabled -RequestTimeout 120 -PickHostNameFromBackendAddress -Probe $probeconfig
# Create a new front-end port
$fp = New-AzureRmApplicationGatewayFrontendPort -Name frontendport01 -Port 80
# Create a new front end IP configuration
$fipconfig = New-AzureRmApplicationGatewayFrontendIPConfig -Name fipconfig01 -PublicIPAddress $publicip
# Create a new listener using the front-end ip configuration and port created earlier
$listener = New-AzureRmApplicationGatewayHttpListener -Name listener01 -Protocol Http -FrontendIPConfiguration $fipconfig -FrontendPort $fp
# Create a new rule
$rule = New-AzureRmApplicationGatewayRequestRoutingRule -Name rule01 -RuleType Basic -BackendHttpSettings $poolSetting -HttpListener $listener -BackendAddressPool $pool
# Define the application gateway SKU to use
$sku = New-AzureRmApplicationGatewaySku -Name Standard_Small -Tier Standard -Capacity 2
# Create the application gateway
$appgw = New-AzureRmApplicationGateway -Name ContosoAppGateway -ResourceGroupName $rg.ResourceGroupName -Location EastUs -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting -Probes $probeconfig -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp -HttpListeners $listener -RequestRoutingRules $rule -Sku $sku
全ての処理がおわると、新しい Application Gateway と Web Apps ができています。
Application Gateway のフロントの DNS に接続すると、Web Apps につながるのが確認できます。
ただ、これを流しただけだと、SKU が Standard になっているので、ポータルから WAF にしてあげて、WAF の設定をするって感じになります。
その辺は、一度やってみた方がいいですよ。
さいごに
今回の記事のネタって、人から教えてもらったんですよねー。
この件の Update 情報ってみた覚えがないんですよねー。
このネタは結構大きいと思うんだけどなぁー


コメント