Azure PowerShell을 사용하여 애플리케이션 게이트웨이를 만들 때 URL 기반 라우팅 규칙을 구성할 수 있습니다. 이 자습서에서는 가상 머신 확장 집합을 사용하여 백 엔드 풀을 만듭니다. 그런 다음 요청 URL 경로에 따라 웹 트래픽을 적절한 백 엔드 풀로 리디렉션하는 URL 라우팅 규칙을 만듭니다. Azure PowerShell을 사용하여 애플리케이션 게이트웨이를 만들 때 고급 URL 기반 라우팅 규칙을 구성할 수 있습니다.
이 자습서에서는 보안 모범 사례, 성능 최적화 및 모니터링 설정을 비롯한 프로덕션 준비 구성에 대해 설명합니다.
이 튜토리얼에서는 다음을 배우게 됩니다:
- 네트워크 인프라 설정
- 경로 기반 라우팅을 사용하여 애플리케이션 게이트웨이 만들기
- URL 리디렉션에 대한 수신기 및 라우팅 규칙 추가
- 백 엔드 풀에 대한 가상 머신 확장 집합 만들기
- 애플리케이션 게이트웨이 라우팅 및 리디렉션 기능 테스트
다음 예제에서는 두 포트 8080 및 8081에서 들어오고 동일한 백 엔드 풀로 리디렉션되는 사이트 트래픽을 보여 줍니다.
필수 조건
원하는 경우 Azure CLI를 사용하여 이 절차를 완료할 수 있습니다.
이 자습서를 시작하기 전에 다음이 있는지 확인하십시오.
- 활성 Azure 구독입니다. 계정이 없는 경우 체험 계정을 만듭니다.
- 로컬에 설치된 Azure PowerShell 모듈 버전 5.4.1 이상 또는 Azure Cloud Shell에 대한 액세스
- 대상 Azure 구독에 대한 기여자 또는 소유자 권한
- Application Gateway 개념 및 PowerShell 스크립팅에 대한 기본적인 이해
참고 항목
Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.
Azure Cloud Shell
Azure는 브라우저를 통해 사용할 수 있는 대화형 셸 환경인 Azure Cloud Shell을 호스트합니다. Cloud Shell에서 Bash 또는 PowerShell을 사용하여 Azure 서비스 작업을 수행할 수 있습니다. 로컬 환경에 아무 것도 설치할 필요 없이 Azure Cloud Shell의 미리 설치된 명령을 사용하여 이 문서의 코드를 실행할 수 있습니다.
Azure Cloud Shell을 시작하려면 다음을 수행합니다.
| 옵션 | 예제/링크 |
|---|---|
| 코드 또는 명령 블록의 오른쪽 상단에서 시도를 선택합니다. 시도를 선택해도 코드 또는 명령이 Cloud Shell에 자동으로 복사되지 않습니다. |
|
| https://shell.azure.com으로 이동하거나 Cloud Shell 시작 단추를 선택하여 브라우저에서 Cloud Shell을 엽니다. |
|
| Azure Portal의 오른쪽 위에 있는 메뉴 모음에서 Cloud Shell 단추를 선택합니다. |
|
Azure Cloud Shell을 사용하려면:
Cloud Shell을 시작합니다.
코드 블록(또는 명령 블록)에서 복사 단추를 선택하여 코드 또는 명령을 복사합니다.
Windows 및 Linux에서 Ctrl+Shift+V를 선택하거나 macOS에서 Cmd+Shift+V를 선택하여 코드 또는 명령을 Cloud Shell 세션에 붙여넣습니다.
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 주소를 만듭니다. 이러한 리소스는 애플리케이션 게이트웨이 및 관련 리소스에 대한 네트워크 연결을 제공합니다.
중요합니다
애플리케이션 게이트웨이 서브넷(myAGSubnet)은 애플리케이션 게이트웨이만 포함할 수 있습니다. 이 서브넷에는 다른 리소스가 허용되지 않습니다. New-AzVirtualNetworkSubnetConfig를 사용하여 myBackendSubnet 및 myAGSubnet에 대한 서브넷 구성을 만듭니다. Application Gateway에는 적절한 작업 및 향후 크기 조정을 위해 최소 /24 CIDR의 전용 서브넷이 필요합니다. 서브넷 구성으로 New-AzVirtualNetwork를 사용하여 myVNet이라는 가상 네트워크를 만듭니다. 마지막으로 New-AzPublicIpAddress를 사용하여 보안 및 성능을 향상시키기 위해 표준 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 구성 및 프런트 엔드 포트 - 앞에서 만든 서브넷을 애플리케이션 게이트웨이에 연결하고 액세스 시 사용할 포트를 할당합니다.
- 기본 풀 - 모든 애플리케이션 게이트웨이에 서버 백 엔드 풀이 하나 이상 있어야 합니다.
- 기본 수신기 및 규칙 - 기본 수신기는 할당된 포트에서 트래픽을 수신 대기하고 기본 규칙은 기본 풀로 트래픽을 보냅니다.
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에서 트래픽을 예상합니다. 다른 수신기는 특정 URL 경로(예: http://203.0.113.1:8080/images/ 또는 http://203.0.113.1:8081/video/.)에서 트래픽을 예상합니다.
이전에 만든 프런트 엔드 구성 및 프런트 엔드 포트가 포함된 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"
Application Gateway 만들기
필요한 지원 리소스를 만들었으므로 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을 사용하여 애플리케이션 게이트웨이에 백 엔드 풀을 추가할 수 있습니다. 이 예제에서는 특정 콘텐츠 형식을 라우팅하기 위해 imagesBackendPool 및 videoBackendPool 을 만듭니다. 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-AzApplicationGatewayPathRuleConfig 및 Add-AzApplicationGatewayUrlPathMapConfig를 사용하여 imagePathRule 및 videoPathRule이라는 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
가상 머신 확장 집합 만들기
이 예제에서는 사용자가 만든 세 개의 백 엔드 풀을 지원하는 세 개의 가상 머신 확장 집합을 만듭니다. 확장 집합의 이름은 myvmss1, myvmss2 및 myvmss3입니다. 각 확장 집합에는 IIS를 설치하는 두 개의 가상 머신 인스턴스가 포함됩니다. IP 설정을 구성할 때 확장 집합을 백 엔드 풀에 할당합니다.
중요합니다
스크립트를 실행하기 전에 <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를 설치하고 서비스하는 백 엔드 풀에 따라 다른 콘텐츠를 표시하도록 구성합니다.
$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를 사용하여 애플리케이션 게이트웨이 테스트:
Get-AzPublicIPAddress를 실행하여 애플리케이션 게이트웨이의 공용 IP 주소를 가져옵니다.
Get-AzPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress공용 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을 http://<ip-address>:8080/images/test.htm로 변경하고 IP 주소를 <ip-address>로 대체하면 다음 예제와 같이 표시됩니다.
URL을 http://<ip-address>:8080/video/test.htm로 변경하고 IP 주소를 <ip-address>로 대체하면 다음 예제와 같이 표시됩니다.
이제 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 경로 기반 리디렉션을 배웠으므로 다음 고급 시나리오를 살펴보세요.