次の方法で共有


Azure PowerShell を使用して URL パスベースのリダイレクトのあるアプリケーション ゲートウェイを作成する

アプリケーション ゲートウェイを作成するときに、Azure PowerShell を使用して URL ベースのルーティング規則を構成できます。 このチュートリアルでは、仮想マシン スケール セットを使用してバックエンド プールを作成します。 次に、要求 URL パスに基づいて Web トラフィックを適切なバックエンド プールにリダイレクトする URL ルーティング規則を作成します。 Azure PowerShell を使用して、アプリケーション ゲートウェイの作成時に高度な URL ベースのルーティング規則を構成できます。

このチュートリアルでは、セキュリティのベスト プラクティス、パフォーマンスの最適化、監視のセットアップなど、運用環境に対応した構成について説明します。

このチュートリアルでは、以下の内容を学習します。

  • ネットワーク インフラストラクチャを設定する
  • パスベースのルーティングを使用してアプリケーション ゲートウェイを作成する
  • URL リダイレクトのリスナーとルーティング規則を追加する
  • バックエンド プールの仮想マシン スケール セットの作成
  • アプリケーション ゲートウェイのルーティングとリダイレクト機能をテストする

次の例は、ポート 8080 と 8081 の両方から送信されてきており、同じバックエンド プールに転送されているサイト トラフィックを示します。

URL ルーティングとリダイレクト アーキテクチャの図。

[前提条件]

好みに応じて、Azure CLI を使ってこの手順を実行することもできます。

このチュートリアルを開始する前に、次のことを確認してください。

  • 有効な Azure サブスクリプション。 アカウントがない場合は、無料アカウントを作成してください。
  • ローカルにインストールされている Azure PowerShell モジュール バージョン 5.4.1 以降、または Azure Cloud Shell へのアクセス
  • ターゲットの Azure サブスクリプションに対する共同作成者または所有者のアクセス許可
  • Application Gateway の概念と PowerShell スクリプトの基本的な理解

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を始めるには、「Azure PowerShell をインストールする」を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

Azure Cloud Shell

Azure では、ブラウザーを介して使用できる対話型のシェル環境、Azure Cloud Shell がホストされています。 Cloud Shell で Bash または PowerShell を使用して、Azure サービスを操作できます。 ローカル環境に何もインストールしなくても、Cloud Shell にプレインストールされているコマンドを使用して、この記事のコードを実行できます。

Azure Cloud Shell を開始するには、次の手順に従います。

オプション 例とリンク
コードまたはコマンド ブロックの右上隅にある [使ってみる] を選択します。 [使ってみる] を選択しても、コードまたはコマンドは Cloud Shell に自動的にはコピーされません。 Azure Cloud Shell の [使ってみる] の例を示すスクリーンショット。
https://shell.azure.com に移動するか、[Cloud Shell を起動する] ボタンを選択して、ブラウザーで Cloud Shell を開きます。 Azure Cloud Shell を起動するボタン。
Azure portal の右上にあるメニュー バーの [Cloud Shell] ボタンを選択します。 Azure portal の [Cloud Shell] ボタンを示すスクリーンショット

Azure Cloud Shell を使用するには、次の手順に従います。

  1. Cloud Shell を起動します。

  2. コード ブロック (またはコマンド ブロック) の [コピー] ボタンを選択し、コードまたはコマンドをコピーします。

  3. Windows と Linux では Ctrl+Shift+V キーを選択し、macOS では Cmd+Shift+V キーを選択して、コードまたはコマンドを Cloud Shell セッションに貼り付けます。

  4. Enter キーを選択して、コードまたはコマンドを実行します。

PowerShell をローカルにインストールして使用する場合、このチュートリアルでは Azure PowerShell モジュール バージョン 5.4.1 以降が必要です。 バージョンを確認するには、Get-Module -ListAvailable Az を実行します。 アップグレードする必要がある場合は、Azure PowerShell モジュールのインストールに関するページを参照してください。 PowerShell をローカルで実行している場合、Connect-AzAccount を実行して Azure との接続を作成することも必要です。

リソース グループを作成する

リソース グループとは、Azure リソースのデプロイと管理に使用する論理コンテナーです。 New-AzResourceGroup を使用して Azure リソース グループを作成します。

# Define variables for consistent naming and easier management
$resourceGroupName = "myResourceGroupAG"
$location = "eastus"

# Create the resource group
New-AzResourceGroup -Name $resourceGroupName -Location $location

# Verify the resource group creation
Write-Output "Resource group '$resourceGroupName' created successfully in '$location'"

ネットワーク リソースを作成する

New-AzVirtualNetworkSubnetConfig を使用して、サブネット構成 myBackendSubnet および myAGSubnet を作成します。 New-AzVirtualNetwork とサブネット構成を使用して、myVNet という名前の仮想ネットワークを作成します。 最後に、 New-AzPublicIpAddress を使用して myAGPublicIPAddress という名前のパブリック IP アドレス を作成します。 これらのリソースは、アプリケーション ゲートウェイとそれに関連付けられているリソースへのネットワーク接続を提供します。

Von Bedeutung

アプリケーション ゲートウェイ サブネット (myAGSubnet) には、アプリケーション ゲートウェイのみを含めることができます。 このサブネットでは、他のリソースは許可されません。 New-AzVirtualNetworkSubnetConfig を使用して、サブネット構成 myBackendSubnet および myAGSubnet を作成します。 Application Gateway には、適切な操作と将来のスケーリングのために、/24 CIDR 以上の専用サブネットが必要です。 New-AzVirtualNetwork とサブネット構成を使用して、myVNet という名前の仮想ネットワークを作成します。 最後に、 New-AzPublicIpAddress を使用して、セキュリティとパフォーマンスを向上させるために、Standard SKU と静的割り当てを使用してパブリック IP アドレスを作成します。

# Create backend subnet configuration with appropriate CIDR for scale sets
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
  -Name myBackendSubnet `
  -AddressPrefix 10.0.1.0/24

# Create Application Gateway subnet - dedicated subnet required
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
  -Name myAGSubnet `
  -AddressPrefix 10.0.2.0/24

New-AzVirtualNetwork `
  -ResourceGroupName myResourceGroupAG `
  -Location eastus `
  -Name myVNet `
  -AddressPrefix 10.0.0.0/16 `
  -Subnet $backendSubnetConfig, $agSubnetConfig

New-AzPublicIpAddress `
  -ResourceGroupName myResourceGroupAG `
  -Location eastus `
  -Name myAGPublicIPAddress `
  -AllocationMethod Dynamic

アプリケーション ゲートウェイの作成

このセクションでは、アプリケーション ゲートウェイをサポートするリソースを作成し、最終的にアプリケーション ゲートウェイを作成します。 作成するリソースは次のとおりです。

  • IP 構成とフロントエンド ポート - 以前に作成したサブネットをアプリケーション ゲートウェイに関連付け、それへのアクセスに使用するポートを割り当てます。
  • 既定のプール - すべてのアプリケーション ゲートウェイには、サーバーのバックエンド プールが 1 つ以上必要です。
  • 既定のリスナーとルール - 既定のリスナーは、割り当てられたポートでトラフィックをリッスンし、既定のルールは、既定のプールにトラフィックを送信します。

IP 構成とフロントエンド ポートの作成

New-AzApplicationGatewayIPConfiguration を使用して、前に作成した myAGSubnet をアプリケーション ゲートウェイに関連付けます。 New-AzApplicationGatewayFrontendIPConfig を使用して、myAGPublicIPAddress をアプリケーション ゲートウェイに割り当てます。 次に、 New-AzApplicationGatewayFrontendPort を使用して HTTP ポートを作成します。

# Get the virtual network and subnet references
$vnet = Get-AzVirtualNetwork `
  -ResourceGroupName myResourceGroupAG `
  -Name myVNet

$subnet=$vnet.Subnets[0]

# Get the public IP address
$pip = Get-AzPublicIpAddress `
  -ResourceGroupName myResourceGroupAG `
  -Name myAGPublicIPAddress

# Create IP configuration for the Application Gateway
$gipconfig = New-AzApplicationGatewayIPConfiguration `
  -Name myAGIPConfig `
  -Subnet $subnet

# Create frontend IP configuration
$fipconfig = New-AzApplicationGatewayFrontendIPConfig `
  -Name myAGFrontendIPConfig `
  -PublicIPAddress $pip

# Create frontend port for HTTP traffic
$frontendport = New-AzApplicationGatewayFrontendPort `
  -Name myFrontendPort `
  -Port 80

Write-Output "Application Gateway IP configurations created successfully"

既定のプールと設定の作成

New-AzApplicationGatewayBackendAddressPool を使用して、アプリケーション ゲートウェイに対して appGatewayBackendPool という名前の既定のバックエンド プールを作成します。 New-AzApplicationGatewayBackendHttpSettings を使用して、バックエンド プールの設定を構成します。

# Create default backend pool
$defaultPool = New-AzApplicationGatewayBackendAddressPool `
  -Name appGatewayBackendPool

# Create backend HTTP settings with optimized configuration
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
  -Name myPoolSettings `
  -Port 80 `
  -Protocol Http `
  -CookieBasedAffinity Enabled `
  -RequestTimeout 120

既定のリスナーとルールの作成

アプリケーション ゲートウェイがバックエンド プールにトラフィックを適切にルーティングできるようにするには、リスナーが必要です。 このチュートリアルでは、さまざまなルーティング シナリオに対して複数のリスナーを作成します。 最初の基本的なリスナーは、ルート URL でトラフィックを待機します。 他のリスナーは、 http://203.0.113.1:8080/images/http://203.0.113.1:8081/video/など、特定の URL パスでトラフィックを受け取ります。

New-AzApplicationGatewayHttpListener と、前に作成したフロントエンド構成およびフロントエンド ポートを使用して、defaultListener という名前のリスナーを作成します。 着信トラフィックに使用するバックエンド プールをリスナーが判断するには、ルールが必要です。 New-AzApplicationGatewayRequestRoutingRule を使用して、rule1 という名前の基本ルールを作成します。

# Create default HTTP listener
$defaultlistener = New-AzApplicationGatewayHttpListener `
  -Name defaultListener `
  -Protocol Http `
  -FrontendIPConfiguration $fipconfig `
  -FrontendPort $frontendport

# Create basic routing rule that directs traffic to default pool
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
  -Name rule1 `
  -RuleType Basic `
  -HttpListener $defaultlistener `
  -BackendAddressPool $defaultPool `
  -BackendHttpSettings $poolSettings `
  -Priority 100

Write-Output "Default listener and routing rule created successfully"

アプリケーション ゲートウェイの作成

必要な関連リソースを作成したら、New-AzApplicationGatewaySku を使用して myAppGateway という名前のアプリケーション ゲートウェイのパラメーターを指定し、New-AzApplicationGateway を使用してそれを作成します。

# Create SKU configuration for Application Gateway v2
$sku = New-AzApplicationGatewaySku `
  -Name Standard_Medium `
  -Tier Standard `
  -Capacity 2

New-AzApplicationGateway `
  -Name myAppGateway `
  -ResourceGroupName myResourceGroupAG `
  -Location eastus `
  -BackendAddressPools $defaultPool `
  -BackendHttpSettingsCollection $poolSettings `
  -FrontendIpConfigurations $fipconfig `
  -GatewayIpConfigurations $gipconfig `
  -FrontendPorts $frontendport `
  -HttpListeners $defaultlistener `
  -RequestRoutingRules $frontendRule `
  -Sku $sku

バックエンド プールとポートの追加

Add-AzApplicationGatewayBackendAddressPool を使用して、バックエンド プールをアプリケーション ゲートウェイに追加できます。 この例では、特定のコンテンツ タイプをルーティングするために imagesBackendPoolvideoBackendPool が作成されます。 プールのフロントエンド ポートは、 Add-AzApplicationGatewayFrontendPort を使用して追加します。 Set-AzApplicationGateway を使用して、アプリケーション ゲートウェイに変更を送信します。

# Get the current Application Gateway configuration
$appgw = Get-AzApplicationGateway `
  -ResourceGroupName myResourceGroupAG `
  -Name myAppGateway

# Add specialized backend pools for different content types
Add-AzApplicationGatewayBackendAddressPool `
  -ApplicationGateway $appgw `
  -Name imagesBackendPool

Add-AzApplicationGatewayBackendAddressPool `
  -ApplicationGateway $appgw `
  -Name videoBackendPool

# Add frontend ports for specialized listeners
Add-AzApplicationGatewayFrontendPort `
  -ApplicationGateway $appgw `
  -Name bport `
  -Port 8080

Add-AzApplicationGatewayFrontendPort `
  -ApplicationGateway $appgw `
  -Name rport `
  -Port 8081

# Apply the configuration changes
Set-AzApplicationGateway -ApplicationGateway $appgw

リスナーと規則の追加

リスナーの追加

Add-AzApplicationGatewayHttpListener を使用して、トラフィックのルーティングに必要な backendListener および redirectedListener という名前のリスナーを追加します。

# Get the current Application Gateway configuration
$appgw = Get-AzApplicationGateway `
  -ResourceGroupName myResourceGroupAG `
  -Name myAppGateway

# Get frontend port references
$backendPort = Get-AzApplicationGatewayFrontendPort `
  -ApplicationGateway $appgw `
  -Name bport

$redirectPort = Get-AzApplicationGatewayFrontendPort `
  -ApplicationGateway $appgw `
  -Name rport

# Get frontend IP configuration
$fipconfig = Get-AzApplicationGatewayFrontendIPConfig `
  -ApplicationGateway $appgw

# Add listeners for different ports
Add-AzApplicationGatewayHttpListener `
  -ApplicationGateway $appgw `
  -Name backendListener `
  -Protocol Http `
  -FrontendIPConfiguration $fipconfig `
  -FrontendPort $backendPort

Add-AzApplicationGatewayHttpListener `
  -ApplicationGateway $appgw `
  -Name redirectedListener `
  -Protocol Http `
  -FrontendIPConfiguration $fipconfig `
  -FrontendPort $redirectPort

# Apply the configuration changes
Set-AzApplicationGateway -ApplicationGateway $appgw

既定の URL パス マップを追加する

URL パス マップにより、特定の URL が特定のバックエンド プールに確実にルーティングされます。 New-AzApplicationGatewayPathRuleConfigAdd-AzApplicationGatewayUrlPathMapConfig を使用して、imagePathRulevideoPathRule という名前の URL パス マップを作成できます。

# Get the current Application Gateway configuration
$appgw = Get-AzApplicationGateway `
  -ResourceGroupName myResourceGroupAG `
  -Name myAppGateway

# Get backend HTTP settings
$poolSettings = Get-AzApplicationGatewayBackendHttpSettings `
  -ApplicationGateway $appgw `
  -Name myPoolSettings

# Get backend address pools
$imagePool = Get-AzApplicationGatewayBackendAddressPool `
  -ApplicationGateway $appgw `
  -Name imagesBackendPool

$videoPool = Get-AzApplicationGatewayBackendAddressPool `
  -ApplicationGateway $appgw `
  -Name videoBackendPool

$defaultPool = Get-AzApplicationGatewayBackendAddressPool `
  -ApplicationGateway $appgw `
  -Name appGatewayBackendPool

# Create path rules for different content types
$imagePathRule = New-AzApplicationGatewayPathRuleConfig `
  -Name imagePathRule `
  -Paths "/images/*" `
  -BackendAddressPool $imagePool `
  -BackendHttpSettings $poolSettings

$videoPathRule = New-AzApplicationGatewayPathRuleConfig `
  -Name videoPathRule `
  -Paths "/video/*" `
  -BackendAddressPool $videoPool `
  -BackendHttpSettings $poolSettings

# Add URL path map configuration
Add-AzApplicationGatewayUrlPathMapConfig `
  -ApplicationGateway $appgw `
  -Name urlpathmap `
  -PathRules $imagePathRule, $videoPathRule `
  -DefaultBackendAddressPool $defaultPool `
  -DefaultBackendHttpSettings $poolSettings

# Apply the configuration changes
Set-AzApplicationGateway -ApplicationGateway $appgw

リダイレクト構成を追加する

Add-AzApplicationGatewayRedirectConfiguration を使用して、リスナーのリダイレクトを構成できます。

# Get the current Application Gateway configuration
$appgw = Get-AzApplicationGateway `
  -ResourceGroupName $resourceGroupName `
  -Name myAppGateway

# Get the target listener for redirection
$backendListener = Get-AzApplicationGatewayHttpListener `
  -ApplicationGateway $appgw `
  -Name backendListener

# Add redirection configuration with query string and path preservation
$redirectConfig = Add-AzApplicationGatewayRedirectConfiguration `
  -ApplicationGateway $appgw `
  -Name redirectConfig `
  -RedirectType Found `
  -TargetListener $backendListener `
  -IncludePath $true `
  -IncludeQueryString $true

# Apply the configuration changes
Set-AzApplicationGateway -ApplicationGateway $appgw

Write-Output "Redirection configuration added successfully"
Write-Output "Redirect type: HTTP 302 Found"
Write-Output "Target: backendListener (Port 8080)"
Write-Output "Preserves: Path and Query String"

リダイレクト URL パス マップを追加する

リダイレクト シナリオ用の個別の URL パス マップを作成します。 このマップはポート 8081 のトラフィックを処理し、特定のパスをポート 8080 の適切なリスナーにリダイレクトします。

# Get the current Application Gateway configuration
$appgw = Get-AzApplicationGateway `
  -ResourceGroupName $resourceGroupName `
  -Name myAppGateway

# Get references to existing configurations
$poolSettings = Get-AzApplicationGatewayBackendHttpSettings `
  -ApplicationGateway $appgw `
  -Name myPoolSettings

$defaultPool = Get-AzApplicationGatewayBackendAddressPool `
  -ApplicationGateway $appgw `
  -Name appGatewayBackendPool

$redirectConfig = Get-AzApplicationGatewayRedirectConfiguration `
  -ApplicationGateway $appgw `
  -Name redirectConfig

# Create path rule for redirection - images traffic will be redirected
$redirectPathRule = New-AzApplicationGatewayPathRuleConfig `
  -Name redirectPathRule `
  -Paths "/images/*" `
  -RedirectConfiguration $redirectConfig

# Add redirection path map configuration
Add-AzApplicationGatewayUrlPathMapConfig `
  -ApplicationGateway $appgw `
  -Name redirectpathmap `
  -PathRules $redirectPathRule `
  -DefaultBackendAddressPool $defaultPool `
  -DefaultBackendHttpSettings $poolSettings

# Apply the configuration changes
Set-AzApplicationGateway -ApplicationGateway $appgw

Write-Output "Redirection URL path map added successfully"
Write-Output "Redirection rule: /images/* on port 8081 -> port 8080"

ルーティング規則の追加

ルーティング規則によって、作成したリスナーに URL マップが関連付けられます。 Add-AzApplicationGatewayRequestRoutingRule を使用して、defaultRule および redirectedRule という名前の規則を追加できます。

$appgw = Get-AzApplicationGateway `
  -ResourceGroupName myResourceGroupAG `
  -Name myAppGateway

$backendlistener = Get-AzApplicationGatewayHttpListener `
  -ApplicationGateway $appgw `
  -Name backendListener

$redirectlistener = Get-AzApplicationGatewayHttpListener `
  -ApplicationGateway $appgw `
  -Name redirectedListener

$urlPathMap = Get-AzApplicationGatewayUrlPathMapConfig `
  -ApplicationGateway $appgw `
  -Name urlpathmap

$redirectPathMap = Get-AzApplicationGatewayUrlPathMapConfig `
  -ApplicationGateway $appgw `
  -Name redirectpathmap

Add-AzApplicationGatewayRequestRoutingRule `
  -ApplicationGateway $appgw `
  -Name defaultRule `
  -RuleType PathBasedRouting `
  -HttpListener $backendlistener `
  -UrlPathMap $urlPathMap

Add-AzApplicationGatewayRequestRoutingRule `
  -ApplicationGateway $appgw `
  -Name redirectedRule `
  -RuleType PathBasedRouting `
  -HttpListener $redirectlistener `
  -UrlPathMap $redirectPathMap

Set-AzApplicationGateway -ApplicationGateway $appgw

仮想マシン スケール セットの作成

この例では、作成した 3 つのバックエンド プールをサポートする 3 つの仮想マシン スケール セットを作成します。 スケール セットの名前は myvmss1myvmss2および myvmss3 です。 各スケール セットには、IIS をインストールする 2 つの仮想マシン インスタンスが含まれています。 スケール セットは、IP 設定を構成するときにバックエンド プールに割り当てます。

Von Bedeutung

スクリプトを実行する前に、 <username><password> を独自の値に置き換えます。 Azure のセキュリティ要件を満たす強力なパスワードを使用します。 セキュリティ上の注意: <username><password> をセキュリティで保護された資格情報に置き換えます。 運用環境のシナリオでは、資格情報管理に Azure Key Vault を使用することを検討してください。

# Get network and Application Gateway references
$vnet = Get-AzVirtualNetwork `
  -ResourceGroupName myResourceGroupAG `
  -Name myVNet

$appgw = Get-AzApplicationGateway `
  -ResourceGroupName myResourceGroupAG `
  -Name myAppGateway

# Get backend pool references
$backendPool = Get-AzApplicationGatewayBackendAddressPool `
  -Name appGatewayBackendPool `
  -ApplicationGateway $appgw

$imagesPool = Get-AzApplicationGatewayBackendAddressPool `
  -Name imagesBackendPool `
  -ApplicationGateway $appgw

$videoPool = Get-AzApplicationGatewayBackendAddressPool `
  -Name videoBackendPool `
  -ApplicationGateway $appgw

# Create three scale sets with improved configuration
for ($i=1; $i -le 3; $i++)
{
  if ($i -eq 1)
  {
     $poolId = $backendPool.Id
  }
  if ($i -eq 2) 
  {
    $poolId = $imagesPool.Id
  }
  if ($i -eq 3)
  {
    $poolId = $videoPool.Id
  }

  $ipConfig = New-AzVmssIpConfig `
    -Name myVmssIPConfig$i `
    -SubnetId $vnet.Subnets[1].Id `
    -ApplicationGatewayBackendAddressPoolsId $poolId

  # Create scale set configuration with modern VM size and settings
  $vmssConfig = New-AzVmssConfig `
    -Location eastus `
    -SkuCapacity 2 `
    -SkuName Standard_DS2 `
    -UpgradePolicyMode Automatic

  # Configure storage profile with Windows Server 2022
  Set-AzVmssStorageProfile $vmssConfig `
    -ImageReferencePublisher MicrosoftWindowsServer `
    -ImageReferenceOffer WindowsServer `
    -ImageReferenceSku 2016-Datacenter `
    -ImageReferenceVersion latest `
    -OsDiskCreateOption FromImage

  Set-AzVmssOsProfile $vmssConfig `
    -AdminUsername <username> `
    -AdminPassword "<password>" `
    -ComputerNamePrefix myvmss$i

  # Add network interface configuration
  Add-AzVmssNetworkInterfaceConfiguration `
    -VirtualMachineScaleSet $vmssConfig `
    -Name myVmssNetConfig$i `
    -Primary $true `
    -IPConfiguration $ipConfig

  New-AzVmss `
    -ResourceGroupName myResourceGroupAG `
    -Name myvmss$i `
    -VirtualMachineScaleSet $vmssConfig

  Write-Output "Virtual Machine Scale Set myvmss$i created successfully"
}

Write-Output "All Virtual Machine Scale Sets created successfully"

IIS のインストール

次のスクリプトは、各スケール セットの仮想マシンに IIS をインストールし、サービスするバックエンド プールに基づいて異なるコンテンツを表示するように IIS を構成します。

$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/Azure/azure-docs-powershell-samples/master/application-gateway/iis/appgatewayurl.ps1"); 
  "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }

# Install IIS on all scale sets
for ($i=1; $i -le 3; $i++)
{
  $vmss = Get-AzVmss -ResourceGroupName myResourceGroupAG -VMScaleSetName myvmss$i

  Add-AzVmssExtension -VirtualMachineScaleSet $vmss `
    -Name "customScript" `
    -Publisher "Microsoft.Compute" `
    -Type "CustomScriptExtension" `
    -TypeHandlerVersion 1.8 `
    -Setting $publicSettings

  Update-AzVmss `
    -ResourceGroupName myResourceGroupAG `
    -Name myvmss$i `
    -VirtualMachineScaleSet $vmss
}

アプリケーション ゲートウェイのテスト

IIS はアプリケーション ゲートウェイを作成する必要はありませんが、このチュートリアルでインストールして、Azure がアプリケーション ゲートウェイを正常に作成したかどうかを確認しました。 IIS を使用してアプリケーション ゲートウェイをテストします。

  1. Get-AzPublicIPAddress を実行して、アプリケーション ゲートウェイのパブリック IP アドレスを取得します。

    Get-AzPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
    
  2. そのパブリック IP アドレスをコピーし、ブラウザーのアドレス バーに貼り付けます。 例えば次が挙げられます。

    • http://203.0.113.1 (ベース URL)
    • http://203.0.113.1:8080/images/test.htm (イメージ パス)
    • http://203.0.113.1:8080/video/test.htm (ビデオのパス)
    • http://203.0.113.1:8081/images/test.htm (リダイレクト テスト)

アプリケーション ゲートウェイのベース URL をテストするときの既定の IIS ウェルカム ページを示すスクリーンショット。

URL を http://<ip-address>:8080/images/test.htm に変更し、IP アドレスを <ip-address> に置き換えます。次の例のように表示されます。

アプリケーション ゲートウェイの /images パスにアクセスするときのイメージ バックエンド プールのテスト ページを示すスクリーンショット。

URL を http://<ip-address>:8080/video/test.htm に変更し、IP アドレスを <ip-address> に置き換えます。次の例のように表示されます。

アプリケーション ゲートウェイの /video パスにアクセスするときのビデオ バックエンド プールのテスト ページを示すスクリーンショット。

次に、URL を http://<ip-address>:8081/images/test.htm に変更し、IP アドレスを <ip-address> に置き換えます。トラフィックは、 http://<ip-address>:8080/imagesのイメージ バックエンド プールにリダイレクトされます。

パフォーマンスの監視

最適なパフォーマンスを得るための主要な Application Gateway メトリックを監視します。

  • 要求数: 処理された要求の合計数
  • 応答時間: 要求の平均応答時間
  • 異常なホスト数: 異常なバックエンド サーバーの数
  • スループット: Application Gateway を介したデータ転送速度

リソースをクリーンアップする

必要がなくなったら、Remove-AzResourceGroup を使用して、リソース グループ、アプリケーション ゲートウェイ、およびすべての関連リソースを削除します。

Remove-AzResourceGroup -Name myResourceGroupAG

次のステップ

Application Gateway での URL パスベースのリダイレクトについて学習したら、次の高度なシナリオについて説明します。

その他のリソース