Azure Application Gateway won't forward Error Code 500 - azure

I face the issue that azure application gateway will show error 502 instead of forwarding the correct error message with HTTP code 500 from the underlying service.
Is that something one could configure? I don't want the application gateway to filter my error messages?

#thomasuebi, by default Azure application gateway sends out periodic probes to backend servers to check their health status. If any backend server does not respond successfully Azure application gateway marks it as unhealthy. When a client request is received for such "unhealthy" backend servers the application gateway does not forward the request to "unhealthy" backend servers and returns a "502 Bad Gateway" error to the requesting client. You can go through this documentation for additional details.
You can also go through this document to set custom error pages instead of 502 bad gateway page.

Related

Azure App Gateway - Backend Health 404 error

I am trying to configure Azure Application Gateway with ADFS. The Backend pool points to ADFS Web Application Proxy. The backend health check is reporting as unhealthy.
I am getting an a error: received invalid status code 404 in the backend servers http response
Everything appears to be configured correctly and I can access the site when bypassing the App Gateway
This was resolved by re-configuring the health probe
In my case with the App Service as a backend pool, I had to create a custom Health probe(http-probe for ex.) to be used in the HTTP setting(http for ex.), where the HTTP setting(http for ex.) is the one configured in the Request Routing Rule.

How to inspect HTTP requests/responses between an Azure App gateway and an App service?

I have the following setup on Azure
Public internet <--> Application gateway <--> App service
I now have a weird issue where the very first request that hits the Application gateway returns "502 - Web server received an invalid response while acting as a gateway or proxy server.". And then if I try the same url again by refreshing the page, the page loads fine.
I had a look at the application logs in my app service but coudln't find anything that would cause the app gateway to return 502. So now I need to know what exactly the gateway is sending to the app service, and what exact response the gateway is getting from the app service that would cause only the first request to fail.
How would i view the http requests that were transmitted between the gateway and app service?
The following article details how to enable web server logging on an Azure App Service which will log raw HTTP request data in the W3C extended log format:
https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs

azure application gateway is not working with 502

I am following the example here on Azure tutorial
https://learn.microsoft.com/en-gb/azure/application-gateway/quick-create-cli
And at the end when I browser for the IP address I got:
502 - Web server received an invalid response while acting as a gateway or proxy server.
Cause of HTTP 502 Error: The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server. (source)
So make sure you are not using proxy in client or server machine.
Issue: Application gateway throws 502.
Application gateway throws 502 when the backend VMs/ resource is unavailable.
Step 1: Check the backend health from portal. It shows the current health status of your backend resource. If it is unhealthy, it shows the reason why it is "unhealthy"
Possible Reason :
NSG/UDR blocking the request reaching the resource
Backend server responds to with respond codes which is not between (200-399)
If it is an end to end SSL , certificate needs to be whitelisted
Step 2: If the backend is healthy, and you still receive 502, make sure the backend is responding to the request sent by Application gateway within 30 seconds(Default value).

Azure Application Gateway error 502 when using application gateway

I followed the docs here https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-create-multisite-portal but still getting the error :
Azure Application Gateway error 502 - Web server received an invalid response while acting as a gateway or proxy server. There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, i
Any help?
About the 502 errors after configuring the application gateway, The main reasons are as follows.
NSG, UDR or Custom DNS is blocking access to backend pool members.
Back-end VMs or instances of virtual machine scale set are not responding to the default health probe.
Invalid or improper configuration of custom health probes.
Azure Application Gateway's back-end pool is not 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.
References: Troubleshooting bad gateway errors in Application Gateway
Just a reminder, after you changing health probe, please check if you select the use custom probe.
Issue: Receiving 502 when you have Web App as the backend pool.
This is how the default probe from Application gateway looks like http/htpps://127.0.0.1:port/
But Web App doesn't respond to localhost, so Application gateway will be receiving 404 for the request sent and it will mark that Web Application unhealthy.
In your scenario, you need to create 3 backend pool where you add one web App in each pool. Then create HTTP setting and enable "Use App Service" check box.
How to enable Use App Service
Then create 3 separate rules to achieve your scenario.
Listener1(test.mydomain.com) ---> HTTP Settings (enable Use App Service) --> Backend Pool(test.mydomain.com)
Listener2(staging.mydomain.com) ---> HTTP Settings (enable Use App Service) --> Backend Pool (staging.mydomain.com )
Listener3(prod.mydomain.com) ---> HTTP Settings (enable Use App Service) --> Backend Pool (prod.mydomain.com)

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.
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!
Error Status Codes(401, 404) returned from pod considered as unhealthy by the azure application gateway and it produces 502 Bad Gateway Error as a response. So you need to modify the health check mechanism of Azure Application Gateway.
Error Codes that are considered to be healthy 200-399 by default
Modify it in "health probes" section inside your Application Gateway Resource, https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-create-probe-portal

Resources