Share via

Azure Application Gateway shows backend unhealthy (certificate CN mismatch) and returns 502 Bad Gateway when routing HTTPS traffic to backend VMs using Private CA

Abhishek Kumar Raj 0 Reputation points
2026-01-19T14:50:48.71+00:00

I am configuring Azure Application Gateway to route traffic from clients to backend virtual machines.

Listener configuration:

Listener port: 443

SSL certificate uploaded at listener: PFX format

Application URL DNS is mapped to the Application Gateway frontend private IP

Backend configuration:

  • Backend pool contains 3 virtual machines,

Backend HTTPS settings:

Protocol: HTTPS

Port: 443

Private CA root certificate uploaded to Application Gateway in .cer format

Health probe:

HTTPS

Backend server certificate installation:

On backend VM, the TLS certificate is installed in the following order, both as separate certificates and also as a combined certificate file:

(End-Entity / Server Certificate)
(Intermediate Certificate)
(Root Certificate)
Issue: After completing the configuration:

Backend health shows Unhealthy

Backend health error message:

The Common Name of the leaf certificate presented by the backend server does not match the Probe or Backend Setting hostname of the application gateway.

  • When accessing the application URL, the response is: 502 Bad Gateway
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,915 Reputation points Microsoft External Staff Moderator
    2026-01-19T15:16:56.2166667+00:00

    Hello Abhishek Kumar Raj

    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:

    Meantime,

    1. Ensure that the Common Name (CN) in the SSL certificate installed on your backend VMs matches the Host name configured in the Application Gateway Backend HTTP settings. If, for example, your Application Gateway is calling the backend using a domain name (like myapp.example.com), the leaf certificate on the backend server also needs to have myapp.example.com as its CN or include it as a Subject Alternative Name (SAN).
    2. Validate your health probe settings. Make sure that the probe's host name corresponds with the CN of the backend server's SSL certificate.
    3. Since you're using a Private CA, you must upload the corresponding Root CA certificate to the Application Gateway. If there's any intermediate certificate involved in your chain, it also needs to be installed correctly on both the backend VM and the Application Gateway.
    4. Ensure the installation order on your backend VM is correct: Leaf certificate first, followed by Intermediate, and finally the Root certificate. You can check this by using OpenSSL commands.
    5. Confirm that the Backend HTTP Settings are set to use HTTPS and that you have the appropriate certificates uploaded for specific backend pools.
    6. Revalidate your full configuration if you paste the CN/SAN.

    Reference Docs:

    Troubleshooting bad gateway errors in Application Gateway

    Troubleshoot backend health issues in Application Gateway)

    If you've tried the above solutions and are still facing issues, here are some follow-up questions that could help narrow down the problem:

    • What hostname are you using in the Application Gateway to connect to the backend VMs?
    • Can you confirm that the SSL certificate has the correct CN or SAN entries that match the hostname?
    • Have you validated that the Root CA certificate used to sign the backend certificates is uploaded to the Application Gateway?
    • Have the health probe settings been verified to ensure the correct path and port are set for the probe?

    Can you please update us if the action plan provided was helpful?

    Should there be any follow-up questions or concerns, please let us know and we shall try to address them.

    Please upvote if you found the information helpful. This will help us and other members of the community as well

    Was this answer helpful?

    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.