Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Application Gateway: Cannot connect to backend server in

Due to a recent layoff I got bombarded to azure admin out of the blue. I am pretty new to this and haven't yet got the chance to follow an admin course.

Facing the following issue: We host a couple of websites on an Azure Windows Server VM running IIS. These are accessible through an application gateway with a public IP. I was asked to add two new listeners for a new part of the website. I created the appropriate targeting in the backend pool, created http and https settings and added the listeners and Rules. However, when browsing to the site, it throws a 502 error and when i check the backend health, it gives below error.

enter image description here

Cannot connect to backend server. Check whether any NSG/UDR/Firewall is blocking access to server. Check if application is running on correct port.

I opened up the appropriate inbound ports on the NSG of the AZ Web interface on the VM and also on the local firewall of the server hosting IIS. AFAIK there are no additional NSG rules on the application gateway.

What am i missing here? :s

like image 992
Dries Van den Bergh Avatar asked Nov 02 '25 05:11

Dries Van den Bergh


1 Answers

I have extensive experience working with Application Gateways and I can tell you that a 502 Bad Gateway means something is definitely wrong at the backend or misconfigured AGW settings - that's what the error says, so nothing surprising. From my experience here are different scenarios I've faced for this error:

  1. Backend server can't be reached due to an NSG Rule controlling access from the AGW subnet to the backend subnet.
  2. Backend server can be reached but the port is not opened at the server's firewall.
  3. Backend server can be reached, port is opened but application is not listening on those ports or application is not even running.
  4. AGW listeners were misconfigured.

Here's what you can try:

First validate whether the Application and VM are fine by trying to access the application from another VM in the same subnet.

Next, try to get a VM in a different subnet and try to access the application, to mimic the AGW trying to connect to the backend. This will help you validate whether your NSGs are properly configured.

Lastly, revisit all the AGW settings and look for any misconfiguration in the listeners or other settings. (Added this based on your comments).

Taking this approach to troubleshooting will quickly help you identify which layer is causing the issue. Also, it would be a good practice to start documenting all AGW errors you get along your journey and also the remediation steps etc. This will help you tremendously in the future - this is not the last time you'll face issues with your AGW!

like image 138
Ked Mardemootoo Avatar answered Nov 03 '25 21:11

Ked Mardemootoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!