An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
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:
- NSG, UDR, or Custom DNS is blocking access to backend pool members.
- Backend VMs or instances of virtual machine scale set aren't responding to the default health probe.
- Invalid or improper configuration of custom health probes.
- Azure Application Gateway's backend pool isn't configured or empty.
- None of the VMs or instances in virtual machine scale set are healthy.
- Request time-out or connectivity issues with user requests.
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.netqueries to 168.63.129.16, not just the app’s default hostname. - Redeploy the Application Gateway so it picks up any recent DNS changes.
- 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.netname
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.