Azure Application Gateway를 사용하면 App Service 앱 또는 기타 다중 테넌트 서비스를 백 엔드 풀 멤버로 사용할 수 있습니다. 이 문서에서는 Application Gateway를 사용하여 App Service 앱을 구성하는 방법을 알아봅니다. Application Gateway에 대한 구성은 App Service에 액세스할 수 있는 방법에 따라 다릅니다.
- 첫 번째 옵션은 Application Gateway와 백 엔드의 App Service 모두에서 사용자 지정 도메인을 사용합니다.
- 두 번째 옵션은 ".azurewebsite.net"로 접미사가 지정된 기본 도메인을 사용하여 Application Gateway가 App Service에 액세스하도록 하는 것입니다.
이 구성은 프로덕션 등급 시나리오에 권장되며 요청 흐름에서 호스트 이름을 변경하지 않는 방식을 충족합니다. 기본 ".Azurewebsite" 도메인에 의존하지 않도록, 사용자 지정 도메인(및 관련 인증서)을 사용할 수 있어야 합니다.
백엔드 풀에서 Application Gateway와 App Service 모두 동일한 도메인 이름을 사용할 경우, 요청 흐름에서 호스트 이름을 재정의할 필요가 없습니다. 백 엔드 웹 애플리케이션은 클라이언트에서 사용한 원래 호스트를 확인합니다.
이 구성은 가장 쉽고 사용자 지정 도메인이 필요하지 않습니다. 따라서 빠르고 편리한 설정이 가능합니다.
App Service에 사용자 지정 도메인이 연결되어 있지 않은 경우, 웹 애플리케이션으로 들어오는 요청의 호스트 헤더를 기본 도메인에 ".azurewebsites.net"이라는 접미사를 추가해 설정해야 하며, 그렇지 않으면 플랫폼이 요청을 제대로 라우팅하지 못할 것입니다.
Application Gateway에서 받은 원래 요청의 호스트 헤더는 백 엔드 App Service의 호스트 이름과 다릅니다.
이 문서에서는 다음 방법을 알아봅니다.
- DNS 구성
- Application Gateway에 백 엔드 풀로 App Service 추가
- App Service 연결을 위한 HTTP 설정 구성
- HTTP 수신기 구성
- 요청 회람 규칙 구성
필수 조건
DNS 구성
이 시나리오의 컨텍스트에서 DNS는 다음 두 위치에서 관련이 있습니다.
- 사용자 또는 클라이언트가 Application Gateway에 대해 사용하는 DNS 이름 및 브라우저에 표시되는 항목
- Application Gateway가 백 엔드의 App Service에 액세스하기 위해 내부적으로 사용하는 DNS 이름
사용자 지정 도메인을 사용하여 사용자 또는 클라이언트를 Application Gateway로 라우팅합니다. Application Gateway용 DNS를 가리키는 CNAME 별칭을 사용하여 DNS를 설정합니다. Application Gateway DNS 주소는 연결된 공용 IP 주소의 개요 페이지에 표시됩니다. 또는 IP 주소를 직접 가리키는 A 레코드를 만듭니다. (Application Gateway V1의 경우 서비스를 중지했다가 시작하면 VIP가 변경될 수 있으므로 이 옵션은 바람직하지 않습니다.)
사용자 지정 도메인 이름을 수신 호스트로 사용하여 Application Gateway의 트래픽을 허용하도록 App Service를 구성해야 합니다. 사용자 지정 도메인을 App Service에 매핑하는 방법에 대한 자세한 내용은 자습서: Azure App Service에 기존 사용자 지정 DNS 이름 매핑을 참조하세요. 도메인을 확인하려면 App Service에서 TXT 레코드를 추가하기만 하면 됩니다. CNAME 또는 A 레코드는 변경할 필요가 없습니다. 사용자 지정 도메인에 대한 DNS 구성은 Application Gateway로 전달됩니다.
HTTPS를 통해 App Service에 대한 연결을 수락하려면 해당 TLS 바인딩을 구성합니다. 자세한 내용은 Azure App Service에서 TLS/SSL 바인딩을 사용하여 사용자 지정 DNS 이름 보안을 참조하여 Azure Key Vault에서 사용자 지정 도메인에 대한 인증서를 끌어오도록 App Service를 구성합니다.
사용자 지정 도메인을 사용할 수 없는 경우 사용자 또는 클라이언트는 게이트웨이의 IP 주소 또는 해당 DNS 주소를 사용하여 Application Gateway에 액세스할 수 있습니다. Application Gateway DNS 주소는 연결된 공용 IP 주소의 개요 페이지에서 찾을 수 있습니다. 사용 가능한 사용자 지정 도메인이 없으면 Application Gateway의 TLS에 공개적으로 서명된 인증서를 사용할 수 없음을 의미합니다. 클라이언트는 자체 서명된 인증서와 함께 HTTP 또는 HTTPS를 사용하도록 제한되며 둘 다 바람직하지 않습니다.
App Service에 연결하기 위해 Application Gateway는 App Service에서 제공하는 기본 도메인(접미사 "azurewebsites.net")을 사용합니다.
백 엔드 풀로 App Service 추가
Azure Portal에서 Application Gateway를 선택합니다.
백 엔드 풀에서 백 엔드 풀을 선택합니다.
대상 유형에서 App Services를 선택합니다.
대상에서 App Service를 선택합니다.
참고 항목
드롭다운은 Application Gateway와 동일한 구독에 있는 앱 서비스만 채웁니다. Application Gateway가 있는 구독과 다른 구독에 있는 앱 서비스를 사용하려는 경우 대상 드롭다운에서 App Services를 선택하는 대신 IP 주소 또는 호스트 이름 옵션을 선택하고 앱 서비스의 호스트 이름(example.azurewebsites.net)을 입력합니다. App Service에서 프라이빗 엔드포인트를 사용하는 경우 프라이빗 엔드포인트의 FQDN 또는 IP 주소를 대신 사용해야 합니다.
저장을 선택합니다.
# Fully qualified default ___domain name of the web app:
$webAppFQDN = "<nameofwebapp>.azurewebsite.net"
# For Application Gateway: both name, resource group and name for the backend pool to create:
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
$appGwBackendPoolNameForAppSvc = "<name for backend pool to be added>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Add a new Backend Pool with App Service in there:
Add-AzApplicationGatewayBackendAddressPool -Name $appGwBackendPoolNameForAppSvc -ApplicationGateway $gw -BackendFqdns $webAppFQDN
# Update Application Gateway with the new added Backend Pool:
Set-AzApplicationGateway -ApplicationGateway $gw
App Service에 대한 HTTP 설정 편집
사용자 지정 도메인 이름을 사용하여 App Service 백 엔드에 액세스하도록 Application Gateway에 지시하는 HTTP 설정이 필요합니다. HTTP 설정은 기본적으로 기본 상태 프로브를 사용합니다. 기본 상태 프로브는 트래픽이 수신되는 호스트 이름으로 요청을 전달하는 반면, 명확하게 정의된 호스트 이름이 없을 경우 상태 프로브는 백엔드 풀에 대해 127.0.0.1을 호스트 이름으로 사용할 수 있습니다. 따라서 올바른 사용자 지정 도메인 이름을 호스트 이름으로 사용하여 구성된 사용자 지정 상태 프로브를 만들어야 합니다.
HTTPS를 사용하여 백 엔드에 연결합니다.
-
HTTP 설정에서 기존 HTTP 설정을 선택하거나 새 설정을 추가합니다.
- 새 HTTP 설정을 만들 때 이름을 지정합니다.
- 포트 443을 사용하여 원하는 백 엔드 프로토콜로 HTTPS를 선택합니다.
- 인증서가 잘 알려진 기관에서 서명한 경우 "사용자 잘 알려진 CA 인증서"에 대해 "예"를 선택합니다. 또는 백 엔드 서버의 인증/신뢰할 수 있는 루트 인증서 추가
- "새 호스트 이름으로 재정의"를 "아니요"로 설정해야 합니다.
- 드롭다운에서 "사용자 지정 프로브"에 대한 사용자 지정 HTTPS 상태 프로브를 선택합니다.
기본("azurewebsites.net") 도메인 이름을 사용하여 App Service 백 엔드에 액세스하도록 Application Gateway에 지시하는 HTTP 설정이 필요합니다. 이렇게 하려면 HTTP 설정이 호스트 이름을 명시적으로 재정의합니다.
-
HTTP 설정에서 기존 HTTP 설정을 선택하거나 새 설정을 추가합니다.
- 새 HTTP 설정을 만들 때 이름을 지정합니다.
- 포트 443을 사용하여 원하는 백 엔드 프로토콜로 HTTPS를 선택합니다.
- 인증서가 잘 알려진 기관에서 서명한 경우 "잘 알려진 사용자 CA 인증서"에 대해 "예"를 선택합니다. 또는 백 엔드 서버의 인증/신뢰할 수 있는 루트 인증서 추가
- "새 호스트 이름으로 재정의"를 "예"로 설정해야 합니다.
- "호스트 이름 재정의"에서 "백 엔드 대상에서 호스트 이름 선택"을 선택합니다. 이 설정은 백 엔드 풀에 구성된 대로 App Service에 대한 요청이 "azurewebsites.net" 호스트 이름을 사용하도록 합니다.
# Configure Application Gateway to connect to App Service using the incoming hostname
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
$customProbeName = "<name for custom health probe>"
$customDomainName = "<FQDN for custom ___domain associated with App Service>"
$httpSettingsName = "<name for http settings to be created>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Add custom health probe using custom ___domain name:
Add-AzApplicationGatewayProbeConfig -Name $customProbeName -ApplicationGateway $gw -Protocol Https -HostName $customDomainName -Path "/" -Interval 30 -Timeout 120 -UnhealthyThreshold 3
$probe = Get-AzApplicationGatewayProbeConfig -Name $customProbeName -ApplicationGateway $gw
# Add HTTP Settings to use towards App Service:
Add-AzApplicationGatewayBackendHttpSettings -Name $httpSettingsName -ApplicationGateway $gw -Protocol Https -Port 443 -Probe $probe -CookieBasedAffinity Disabled -RequestTimeout 30
# Update Application Gateway with the new added HTTP settings and probe:
Set-AzApplicationGateway -ApplicationGateway $gw
# Configure Application Gateway to connect to backend using default App Service hostname
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
$httpSettingsName = "<name for http settings to be created>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Add HTTP Settings to use towards App Service:
Add-AzApplicationGatewayBackendHttpSettings -Name $httpSettingsName -ApplicationGateway $gw -Protocol Https -Port 443 -PickHostNameFromBackendAddress -CookieBasedAffinity Disabled -RequestTimeout 30
# Update Application Gateway with the new added HTTP settings and probe:
Set-AzApplicationGateway -ApplicationGateway $gw
트래픽을 허용하려면 수신기를 구성해야 합니다. 수신기에 대한 자세한 내용은 Application Gateway 수신기 구성을 참조하세요.
- "수신기" 섹션을 열고 "수신기 추가"를 선택하거나 편집할 기존 섹션을 선택합니다.
- 새 수신기의 경우: 이름을 지정합니다.
- "프런트 엔드 IP"에서 수신 대기할 IP 주소를 선택합니다.
- "포트"에서 443을 선택합니다.
- "프로토콜"에서 "HTTPS"를 선택합니다.
- "인증서 선택"에서 "Key Vault에서 인증서 선택"을 선택합니다. 자세한 내용은 관리 ID를 할당하고 Key Vault 에 대한 권한을 제공하는 방법에 대한 자세한 내용은 Key Vault 사용을 참조하세요.
- 인증서에 이름을 지정합니다.
- 관리 ID를 선택합니다.
- 인증서를 가져올 위치에서 Key Vault를 선택합니다.
- 인증서 선택
- "수신기 유형"에서 "기본"을 선택합니다.
- "추가"를 선택하여 수신기 추가
사용 가능한 사용자 지정 도메인 또는 연결된 인증서가 없다고 가정하고 포트 80에서 HTTP 트래픽을 수신 대기하도록 Application Gateway를 구성합니다. 또는 자체 서명 인증서 만들기 방법에 대한 지침을 참조하세요.
- "수신기" 섹션을 열고 "수신기 추가"를 선택하거나 편집할 기존 섹션을 선택합니다.
- 새 수신기의 경우: 이름을 지정합니다.
- "프런트 엔드 IP"에서 수신 대기할 IP 주소를 선택합니다.
- "포트"에서 80을 선택합니다.
- "프로토콜"에서 "HTTP"를 선택합니다.
# This script assumes that:
# - a certificate was imported in Azure Key Vault already
# - a managed identity was assigned to Application Gateway with access to the certificate
# - there is no HTTP listener defined yet for HTTPS on port 443
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
$appGwSSLCertificateName = "<name for ssl cert to be created within Application Gateway"
$appGwSSLCertificateKeyVaultSecretId = "<key vault secret id for the SSL certificate to use>"
$httpListenerName = "<name for the listener to add>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Create SSL certificate object for Application Gateway:
Add-AzApplicationGatewaySslCertificate -Name $appGwSSLCertificateName -ApplicationGateway $gw -KeyVaultSecretId $appGwSSLCertificateKeyVaultSecretId
$sslCert = Get-AzApplicationGatewaySslCertificate -Name $appGwSSLCertificateName -ApplicationGateway $gw
# Fetch public ip associated with Application Gateway:
$ipAddressResourceId = $gw.FrontendIPConfigurations.PublicIPAddress.Id
$ipAddressResource = Get-AzResource -ResourceId $ipAddressResourceId
$publicIp = Get-AzPublicIpAddress -ResourceGroupName $ipAddressResource.ResourceGroupName -Name $ipAddressResource.Name
$frontendIpConfig = $gw.FrontendIpConfigurations | Where-Object {$_.PublicIpAddress -ne $null}
$port = New-AzApplicationGatewayFrontendPort -Name "port_443" -Port 443
Add-AzApplicationGatewayFrontendPort -Name "port_443" -ApplicationGateway $gw -Port 443
Add-AzApplicationGatewayHttpListener -Name $httpListenerName -ApplicationGateway $gw -Protocol Https -FrontendIPConfiguration $frontendIpConfig -FrontendPort $port -SslCertificate $sslCert
# Update Application Gateway with the new HTTPS listener:
Set-AzApplicationGateway -ApplicationGateway $gw
대부분의 경우 포트 80에서 HTTP에 대한 공용 수신기가 있습니다. 아래 스크립트는 아직 그렇지 않은 경우 하나를 만듭니다.
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
$httpListenerName = "<name for the listener to add if not exists yet>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Check if HTTP listener on port 80 already exists:
$port = $gw.FrontendPorts | Where-Object {$_.Port -eq 80}
$listener = $gw.HttpListeners | Where-Object {$_.Protocol.ToString().ToLower() -eq "http" -and $_.FrontendPort.Id -eq $port.Id}
if ($listener -eq $null){
$frontendIpConfig = $gw.FrontendIpConfigurations | Where-Object {$_.PublicIpAddress -ne $null}
Add-AzApplicationGatewayHttpListener -Name $httpListenerName -ApplicationGateway $gw -Protocol Http -FrontendIPConfiguration $frontendIpConfig -FrontendPort $port
# Update Application Gateway with the new HTTPS listener:
Set-AzApplicationGateway -ApplicationGateway $gw
}
이전에 구성된 백 엔드 풀 및 HTTP 설정에서는 요청 라우팅 규칙을 설정하여 수신기에서 트래픽을 가져와서 HTTP 설정을 사용하여 백 엔드 풀로 라우팅할 수 있습니다. 이를 위해 기존 라우팅 규칙에 아직 바인딩되지 않은 HTTP 또는 HTTPS 수신기를 사용할 수 있는지 확인합니다.
- "규칙"에서 새 "요청 라우팅 규칙"을 추가하려면 선택합니다.
- 규칙에 이름을 지정합니다.
- 기존 라우팅 규칙에 아직 바인딩되지 않은 HTTP 또는 HTTPS 수신기 선택
- "백 엔드 대상"에서 App Service가 구성된 백 엔드 풀을 선택합니다.
- Application Gateway가 App Service 백 엔드에 연결해야 하는 HTTP 설정을 구성합니다.
- "추가"를 선택하여 이 구성을 저장합니다.
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
$httpListenerName = "<name for existing http listener (without rule) to route traffic from>"
$httpSettingsName = "<name for http settings to use>"
$appGwBackendPoolNameForAppSvc = "<name for backend pool to route to>"
$reqRoutingRuleName = "<name for request routing rule to be added>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Get HTTP Settings:
$httpListener = Get-AzApplicationGatewayHttpListener -Name $httpListenerName -ApplicationGateway $gw
$httpSettings = Get-AzApplicationGatewayBackendHttpSettings -Name $httpSettingsName -ApplicationGateway $gw
$backendPool = Get-AzApplicationGatewayBackendAddressPool -Name $appGwBackendPoolNameForAppSvc -ApplicationGateway $gw
# Add routing rule:
Add-AzApplicationGatewayRequestRoutingRule -Name $reqRoutingRuleName -ApplicationGateway $gw -RuleType Basic -BackendHttpSettings $httpSettings -HttpListener $httpListener -BackendAddressPool $backendPool
# Update Application Gateway with the new routing rule:
Set-AzApplicationGateway -ApplicationGateway $gw
테스트
이렇게 하기 전에 백 엔드 상태가 정상으로 표시되는지 확인합니다.
"백 엔드 상태" 섹션을 열고 "상태" 열에 HTTP 설정 및 백 엔드 풀의 조합이 "정상"으로 표시되는지 확인합니다.
이제 Application Gateway IP 주소 또는 IP 주소에 연결된 DNS 이름을 사용하여 웹 애플리케이션을 찾습니다. 둘 다 Application Gateway "개요" 페이지에서 "Essentials" 아래의 속성으로 찾을 수 있습니다. 또는 공용 IP 주소 리소스에는 IP 주소 및 연결된 DNS 이름도 표시됩니다.
애플리케이션을 테스트할 때 다음과 같은 잠재적인 증상 목록에 주의하세요.
- Application Gateway 대신 직접 ".azurewebsite.net"을 가리키는 리디렉션
- ".azurewebsite.net"에 직접 액세스를 시도하는 인증 리디렉션이 포함되어 있습니다.
- 도메인 바운딩된 쿠키가 백 엔드로 전달되지 않음
- App Service에서 "ARR 선호도" 설정 의 사용을 포함합니다.
위의 조건(아키텍처 센터에 자세히 설명됨)은 웹 애플리케이션이 호스트 이름 다시 쓰기를 잘 처리하지 못한다는 것을 나타냅니다. 이것은 일반적으로 볼 수 있습니다. 이를 처리하는 권장 방법은 사용자 지정 도메인을 사용하여 App Service와 함께 Application Gateway를 구성하는 지침을 따르는 것입니다.
Application Gateway에서 App Service 문제 해결도 참조하세요.
"백 엔드 상태" 섹션을 열고 "상태" 열에 HTTP 설정 및 백 엔드 풀의 조합이 "정상"으로 표시되는지 확인합니다.
이제 백 엔드에서 Application Gateway 및 App Service와 연결한 사용자 지정 도메인을 사용하여 웹 애플리케이션으로 이동합니다.
백 엔드 및 HTTP 설정의 백 엔드 상태가 "정상"으로 표시되는지 확인합니다.
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Check health:
Get-AzApplicationGatewayBackendHealth -ResourceGroupName $rgName -Name $appGwName
구성을 테스트하기 위해 사용자 지정 도메인을 사용하여 Application Gateway를 통해 App Service에서 콘텐츠를 요청합니다.
$customDomainName = "<FQDN for custom ___domain pointing to Application Gateway>"
Invoke-WebRequest $customDomainName
백 엔드 및 HTTP 설정의 백 엔드 상태가 "정상"으로 표시되는지 확인합니다.
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Check health:
Get-AzApplicationGatewayBackendHealth -ResourceGroupName $rgName -Name $appGwName
구성을 테스트하기 위해 IP 주소를 사용하여 Application Gateway를 통해 App Service에서 콘텐츠를 요청합니다.
$rgName = "<name of resource group for App Gateway>"
$appGwName = "<name of the App Gateway>"
# Get existing Application Gateway:
$gw = Get-AzApplicationGateway -Name $appGwName -ResourceGroupName $rgName
# Get ip address:
$ipAddressResourceId = $gw.FrontendIPConfigurations.PublicIPAddress.Id
$ipAddressResource = Get-AzResource -ResourceId $ipAddressResourceId
$publicIp = Get-AzPublicIpAddress -ResourceGroupName $ipAddressResource.ResourceGroupName -Name $ipAddressResource.Name
Write-Host "Public ip address for Application Gateway is $($publicIp.IpAddress)"
Invoke-WebRequest "http://$($publicIp.IpAddress)"
애플리케이션을 테스트할 때 다음과 같은 잠재적인 증상 목록에 주의하세요.
- Application Gateway 대신 ".azurewebsites.net"을 직접 가리키는 리디렉션
- 여기에는 ".azurewebsites.net"에 직접 액세스를 시도하는 App Service 인증 리디렉션이 포함됩니다.
- 도메인 바운딩된 쿠키가 백 엔드로 전달되지 않음
- 여기에는 App Service의 "ARR 선호도" 설정 사용이 포함됩니다.
위의 조건(아키텍처 센터에 자세히 설명됨)은 웹 애플리케이션이 호스트 이름 다시 쓰기를 잘 처리하지 못한다는 것을 나타냅니다. 이것은 일반적으로 볼 수 있습니다. 이 조건을 처리하는 권장 방법은 사용자 지정 도메인을 사용하여 App Service에서 Application Gateway 구성에 대한 지침을 따르는 것입니다.
Application Gateway에서 App Service 문제 해결도 참조하세요.
액세스 제한
이 예제에서 배포된 웹앱은 인터넷에서 직접 액세스할 수 있는 공용 IP 주소를 사용합니다. 따라서 새로운 기능을 배우고 새로운 것을 시도할 때 문제를 해결하는 데 도움이 됩니다. 하지만 프로덕션 환경에 기능을 배포하려는 경우 더 많은 제한을 추가하려고 합니다. 다음 옵션을 살펴보세요.
-
서비스 엔드포인트 기반 액세스 제한 규칙을 구성합니다. 이렇게 하면 원본 주소가 Application Gateway에서 온 것인지 확인하여 앱에 대한 인바운드 액세스를 잠글 수 있습니다.
-
Azure App Service 고정 IP 제한을 사용합니다. 웹앱이 애플리케이션 게이트웨이의 트래픽만 수신하도록 웹앱을 제한할 수 있습니다. 앱 서비스 IP 제한 기능을 사용하여 액세스할 수 있는 유일한 주소로 애플리케이션 게이트웨이 VIP를 나열할 수 있습니다.