Question

Difficulty: MediumConfigure Azure Application Gateway

An organization deploys an Azure App Service named app-prod-01 that hosts a web application at the default URL app-prod-01.azurewebsites.net. You configure an Azure Application Gateway v2 to publish the web application to the public internet using the custom domain name www.contoso.com. You configure a DNS CNAME record for www.contoso.com pointing to the public IP address of the Application Gateway. You add app-prod-01.azurewebsites.net as a target in the backend pool of the Application Gateway. When users attempt to access https://www.contoso.com, they receive an HTTP 502 (Bad Gateway) error. What should you do on the Application Gateway to resolve the error?

  1. In the Backend Settings of the Application Gateway, enable the host name override and choose to pick the host name from the backend target.Answer
  2. B
    In the App Service Plan configuration, scale down the pricing tier to Free (F1) to disable the default custom domain hostname verification.
  3. C
    Create a User-Defined Route (UDR) on the Application Gateway subnet that specifies the App Service IP address as the next hop with a type of Virtual Network Gateway.
  4. D
    Create an inbound security rule in the Network Security Group (NSG) associated with the Application Gateway subnet that denies traffic from the GatewayManager service tag with a priority of 150.

Answer

In the Backend Settings of the Application Gateway, enable the host name override and choose to pick the host name from the backend target.
Azure App Service requires that the incoming HTTP host header matches either its default '*.azurewebsites.net' domain name or an explicitly configured custom domain name. By default, Azure Application Gateway preserves the original host header from the client request (in this case, 'www.contoso.com') when forwarding traffic to the backend. Since the App Service is not configured with 'www.contoso.com', it rejects the request, causing the Application Gateway to return an HTTP 502 Bad Gateway error. Enabling the host name override option and picking the host name from the backend target in the Backend Settings ensures that the Application Gateway rewrites the host header to 'app-prod-01.azurewebsites.net' before forwarding the request.

Step-by-Step Solution

1
Identify the cause of the HTTP 502 (Bad Gateway) error when integrating Application Gateway with Azure App Service.
The App Service expects incoming requests to have a host header matching its default domain (app-prod-01.azurewebsites.net), but the Application Gateway forwards the original client host header (www.contoso.com).
By default, Application Gateway does not modify the host header of forwarded requests.
2
Configure the Application Gateway to override the host header.
Modify the Backend Settings associated with the App Service backend pool.
Backend Settings define how the Application Gateway connects and forwards requests to the backend servers.
3
Enable the 'Override with new host name' option and select 'Pick host name from backend target'.
The Application Gateway now dynamically overrides the host header in forwarded requests with the domain name of the App Service.
This allows the App Service to successfully match the host header, resolve the request, and prevent the HTTP 502 error.

Key Concept

Configuring backend settings and host header overrides in Azure Application Gateway for App Service integration
Rate this question