Share via

Application Gateway returns 502 for App Service backend by FQDN

Ievgen Kurinnyi 20 Reputation points
2026-03-20T22:34:19.43+00:00

Problem

Azure Application Gateway returns 502 Bad Gateway for a custom domain routed to an Azure Web App (App Service). The Web App is reachable directly, but Application Gateway backend health for the App Service endpoint remains in error state when the backend is configured by FQDN.

Key symptoms

  • https://ecxportalpoc.ecxecx.com/ returns 502 Bad Gateway
  • Application Gateway backend health shows:
    • The backend health status could not be retrieved...
  • Connection Troubleshoot reported:
    • Local Error: DNSResolution

Confirmed working

  • Application Gateway frontend is reachable and presents the expected certificate:
subject: CN=ecxportalpoc.ecxecx.com
  • Public DNS for the custom domain now points to the Application Gateway public IP
  • Custom DNS server 1.0.0.68 in the VNet forwards unresolved Azure records to 168.63.129.16
  • DNS from a VM in the same VNet resolves both:
    • the custom domain chain correctly
    • the default Web App hostname to the correct IP
  • Direct backend test to App Service succeeds:
curl -Ik https://ecxsp06pwap04temp-cwhbcefqcrg9fnch.westus-01.azurewebsites.net/ -H 'Host: ecxportalpoc.ecxecx.com'

Response:

HTTP/1.1 200 OK
  • Direct TLS/SNI test to App Service also succeeds:
openssl s_client -connect ecxsp06pwap04temp-cwhbcefqcrg9fnch.westus-01.azurewebsites.net:443 -servername ecxportalpoc.ecxecx.com

Result:

subject=CN=ecxportalpoc.ecxecx.com
Verify return code: 0 (ok)

Configuration checks already done

  • Listener, backend pool, backend settings, health probe, and rule were reviewed and appear correct
  • Application Gateway was stopped and started after DNS correction
  • NSG and route table on the Application Gateway subnet were reviewed with no obvious issue found

Important observation

For test purposes, Application Gateway health works if the backend pool is configured with the direct App Service IP. This is not a valid production solution because App Service backend IP is not a stable target.

Request

Please help identify why Application Gateway cannot successfully resolve/probe/route to the App Service backend by FQDN in this configuration, even though:

  • DNS resolution works through the configured custom DNS path
  • Direct HTTPS and TLS/SNI tests to the App Service backend succeed
  • The same backend works when configured by IP only

Questions

  1. Why does Application Gateway backend health fail for the App Service FQDN while direct backend tests succeed?
  2. Is there any known issue or additional requirement for Application Gateway with App Service backend resolution through custom DNS forwarding to 168.63.129.16?
  3. Is there any hidden NSG/UDR/control-plane dependency that can cause this exact health error and 502 behavior?
Azure Application Gateway
Azure Application Gateway

An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.


1 answer

Sort by: Most helpful
  1. Ganesh Patapati 11,530 Reputation points Microsoft External Staff Moderator
    2026-03-27T07:59:36.0166667+00:00

    Hello Ievgen Kurinnyi

    Thanks for the reply!

    After you configure an application gateway, one of the errors that you may see is Server Error: 502 - Web server received an invalid response while acting as a gateway or proxy server. This error may happen for the following main reasons:

    NOTE: Enable and inspect the BackendHealth diagnostics

    • Turn on the ApplicationGatewayBackendHealth diagnostic category (Log Analytics or Storage).
    • Look at the records for your App Service backend.
    • In Backend Server – this is the exact FQDN AG is trying to resolve
    • HealthStatusDetail – if it mentions “DNSResolution,” it means the gateway itself can’t resolve that name.

    Verify DNS from the gateway’s perspective

      • Make sure your AG’s subnet DNS servers list includes your custom DNS forwarder (12.0.0.68).
      • Confirm that your forwarder is sending all *.azurewebsites.net queries to 168.63.129.16, not just the app’s default hostname.
      • Redeploy the Application Gateway so it picks up any recent DNS changes.
    1. If DNS is truly the blocker, pick one of these production-grade solutions: Option A – Conditional forwarder on your DNS server for azurewebsites.net → 168.63.129.16 Option B – Azure Private DNS zone for your custom domain (or for the App Service FQDN), linked to the VNet, with a CNAME to the *.azurewebsites.net name

    Once AG can resolve the App Service default FQDN natively, the health probe will turn green and the 502s will disappear.

    Microsoft docs: How to Troubleshoot Bad Gateway (502) error in Application Gateway


    Hope that helps!

    If you are still facing an issue, please share the required details in a private message so we can connect 1:1 to resolve your query.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.