3
votes

I have set up a new application Gateway following the MS document. I have configured the back end pool .it is connected to an App Service via FQDN. Somehow I receive 502 immediately every time I browse to the application gateway. Browsing to the website directly works with no issues .

1
Did you configure health probes? Without health probes all your backend is considered dead, that's why the 502.evilSnobu
I added a custom health probe still didn't fix the issue which is very frustrating. I then ran the recommended MS Power shell script to create application gateway and it worked . I went through every component and compared the only difference is because the second one was created via power-shell the host field of the Health Probe was left empty. whereas creating it via portal you have to have a host name. I say this is a bug with creation of Application Gateway via Azure portalAzure Ninja
Consider your backend being a load balancer fronting a bunch of web servers hosting multiple sites. Would you agree with me that you need to be explicit with the Host header, at all times?evilSnobu

1 Answers

3
votes

I have resolved this issue. Here is the solution.

If you have web apps in your backend pools you CAN'T set up the health probes via Azure portal.

You need to set them up via resource templates or Powershell. The key is that you need to leave the host field empty and set -PickHostNameFromBackendAddress property.

The two lines below did the magic to make the 502s go away

# 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    

# Define the backend http settings
$poolSetting = New-AzureRmApplicationGatewayBackendHttpSettings -Name appGatewayBackendHttpSettings -Port 80 -Protocol Http -CookieBasedAffinity Disabled -RequestTimeout 120 -PickHostNameFromBackendAddress -Probe $probeconfig