Search code examples
azuregatewayerror-code

Azure application gateway throws 502 when application sends 401


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.


Solution

  • 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!