1
votes

Azure application gateway displays 502 bad gateway error, while application returns 401 or 500 errors. It should send whatever the application sends but by default it sends 502. Any idea what happen and any configuration or code change suggestions?

EDIT: We are using node js for our API service. When a client tries to hit the endpoint without any auth header, then the service will return 401 error. This error is transformed into 502 when it's passing the App gateway.

1
If your application is returning 400 or higher, then the gateway is going to remove that app endpoint as a result of the default health probe. If you're doing this for all the endpoints behind the gateway, then the application gateway won't have any endpoints to send the request to and therefore is likely why you're getting a 502. It's not clear what your scenario is. More information on how your health probe is configured, where in your application you return 401 or 500, and why would be helpful.Rick Rainey
@RickRainey I have added the additional info. into the question.Dhanendran Rajagopal

1 Answers

3
votes

General Workflow

When application gateway receives a status code greater than 399, then it will consider there were some issues with the servers and it will remove the server from the pool. After sometime it will check the application status, if it is returning status code lesser than 400 then it add the server to pool.

By default application gateway will be configured to check the app health by making a HTTP/HTTPS request.

Cause

Application may encountered any errors or any authentication errors may result in different error codes. This might caused the application gateway result in 502 error.

Probe

We can configure a special file/end point to check the application/database health. This configuration should be in the probe file.

Useful resource

https://azure.microsoft.com/en-us/documentation/articles/application-gateway-create-probe-classic-ps/

https://azure.microsoft.com/en-us/documentation/articles/application-gateway-probe-overview/

Hope it helps!