title: Application Gateway 502 error when configuring it for Azure Web App
body: <p><strong>Scenario</strong>:</p>
  
  <p>Configured Azure Application Gateway to route traffic to different Azure Web Apps to leverage the Web Application Firewall (WAF). </p>
  
  <p>Initial configuration worked fine except that the final URL in the browser is the {mysite}.azurewebsites.net. I want this to be the custom domain name {subdomain}.{mysite}.com. This was configured by having the backend pool bound to an app service. Changing it to FQDN is not working. Screen shots below.</p>
  
  <p>CNAME is already pointing to the gateway. </p>
  
  <p><strong>Desired result</strong></p>
  
  <p>When someone hits {subdomain}.{mysite}.com (which is already configured to point to the gateway) I should get {subdomain}.{mysite}.com not {mysite}.azurewebsites.net</p>
  
  <p><strong>Current setup</strong>:</p>
  
  <p>The gateway is configured with a multi-site listener with its rule pointing to a backend pool and also bound to the http setting. </p>
  
  <p>Listener is listening on {subdomain}.{mysite}.com</p>
  
  <p>Backend pool config
  <a href="https://i.stack.imgur.com/INTMi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/INTMi.png" alt="pool config"></a></p>
  
  <p>Probe config
  <a href="https://i.stack.imgur.com/ZkV8M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZkV8M.png" alt="probe config"></a></p>
  
  <p>Http setting config
  <a href="https://i.stack.imgur.com/1LXUg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1LXUg.png" alt="setting config"></a></p>
  
  <p>The following links provide some partial answers/configurations but none of them worked for me.
  <a href="https://stackoverflow.com/questions/46046056/application-gateway-502-error">Application Gateway - 502 error</a></p>
  
  <p><a href="https://docs.microsoft.com/en-us/azure/application-gateway/troubleshoot-app-service-redirection-app-service-url" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/application-gateway/troubleshoot-app-service-redirection-app-service-url</a></p>
  
  <p><a href="https://docs.microsoft.com/en-us/azure/application-gateway/create-web-app" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/application-gateway/create-web-app</a></p>
  
  <h1><strong>UPDATE</strong></h1>
  
  <p>Here are a list of steps used to configure an azure app service with a custom domain behind the Azure Application Gateway and WAF (Web Application Firewall) using the azure portal UI.</p>
  
  <ol>
  <li>Configure a Backend pool with target pointing to your App Service.</li>
  <li><p>Configure Health Probe with the following settings</p>
  
  <ul>
  <li>Protocol: HTTP or HTTPS</li>
  <li>Host: {appservice}.azurewebsites.net</li>
  <li>Path: /</li>
  </ul></li>
  <li><p>Configure Http setting</p>
  
  <ul>
  <li>Use App Service unchecked.</li>
  <li>Use custom probe <strong>checked</strong>.</li>
  <li>Pick host name from backend address unchecked (you might have to check this to configure the rule and then uncheck it).</li>
  </ul></li>
  <li><p>Configure listener</p>
  
  <ul>
  <li>HostName: {subdomain}.{domain}.com (your domain)</li>
  </ul></li>
  <li><p>Configure basic rule</p>
  
  <ul>
  <li>Bind it to the appropriate http setting, backend pool and listener</li>
  <li>Caveat: If there are no http settings with Pick host name from backend checked, you might need to change it, attach it, and then remove that flag again.</li>
  </ul></li>
  </ol>