# 502 Bad Gateway on Azure

> Azure 502s come from App Service, Application Gateway or Front Door. Find the layer, then fix probes, NSG and route rules, request time-outs or app crashes.

Canonical: https://scaplet.com/errors/http/502/azure

Guide Microsoft Azure Error · HTTP status codes

Azure 502s come from App Service, Application Gateway or Front Door. Find the layer, then fix probes, NSG and route rules, request time-outs or app crashes.

5 min

read

4

sources

Nov 1, 2026

updated

Scaplet Editorial Team

author

502 5xx · Server error

The short answer

A 502 on Azure is produced by whichever gateway sits in front of your app. For Application Gateway, Microsoft lists blocked network paths, a default probe that can't reach the backend, a backend time-out (20 seconds by default), an empty or unhealthy pool, and a certificate mismatch. For App Service, the usual causes are slow requests, high memory or CPU, or an unhandled exception. Find the layer first.

1. [Three Azure layers, three kinds of 502](#three-azure-layers-three-kinds-of-502)
2. [Check it in 2 minutes](#check-it-in-2-minutes)
3. [Application Gateway: the six documented causes](#application-gateway-the-six-documented-causes)
4. [Application Gateway: a time-out is a 502 on v1 and a 504 on v2](#application-gateway-a-time-out-is-a-502-on-v1-and-a-504-on-v)
5. [App Service: observe, collect, mitigate](#app-service-observe-collect-mitigate)

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%2Fazure%20(%22502%20Bad%20Gateway%20on%20Azure%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%2Fazure%20(%22502%20Bad%20Gateway%20on%20Azure%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%2Fazure%20(%22502%20Bad%20Gateway%20on%20Azure%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%2Fazure%20(%22502%20Bad%20Gateway%20on%20Azure%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_Which Azure layer, and where it is documented

## Three Azure layers, three kinds of 502

Azure has no single 502 source. Which layer answered decides where to look, and mixing them up wastes the most time. The same public URL may pass through a CDN and a gateway before it reaches App Service, so test each hop on its own hostname. Microsoft's Front Door guide gives the right method: send the request to your origin directly, then through the front layer, and compare.

Layer

### Application Gateway

Typical cause Microsoft documents

Backend unreachable or unhealthy, or backend time-out exceeded

Start here

Gateway section below

Layer

### App Service

Typical cause Microsoft documents

Requests take a long time, the app uses high memory or CPU, or an exception stops it responding

Start here

App Service section below

Layer

### Front Door

Typical cause Microsoft documents

Origin is an IP address, certificate name mismatch, or incomplete certificate chain on [HTTPS](/glossary/https)

Start here

[Azure Front Door 502](/errors/cdn/azure-front-door-502)

An example stack: each hop can return its own 502

```
client -> Front Door -> Application Gateway -> App Service or VM -> your app (TLS to origin) (probes, time-out) (memory, CPU, crash)
```

_02_Check it

## Check it in 2 minutes

Compare the same path through and around the gateway. The first command uses a public test service so you can see the output; replace the URLs for the others.

Your stack: origin directly versus through the gateway (needs your URLs)

```
curl -sS -o /dev/null -w "origin: %{http_code} %{time_total}s\n" https://your-app.azurewebsites.net/ curl -sS -o /dev/null -w "gateway: %{http_code} %{time_total}s\n" https://www.your-domain.example/ # origin 200 and gateway 502: gateway config, probes or certificate # origin 5xx or slow: the app, not the gateway
```

Read the times as well as the codes. A gateway 502 that arrives close to its configured request time-out points at a slow backend. Application Gateway's default is 20 seconds, according to the Microsoft troubleshooting article.

Public test endpoint: read a 502 status

```
curl -sS -o /dev/null -w "%{http_code}\n" https://httpbin.org/status/502 # observed: 502
```

_03_Causes and first checks

## Application Gateway: the six documented causes

Microsoft's article gives the browser text as "Server Error: 502 - Web server received an invalid response while acting as a gateway or proxy server" and lists six reasons. Four of them are about probes and the network path, so start with the probe.

Cause

### NSG, user-defined route or custom DNS blocks the backend

First check

Effective NSG and route table on the backend NIC; whether the VNet's custom DNS resolves the backend FQDN

Cause

### The default health probe cannot reach the backend VMs

First check

A default site must listen at 127.0.0.1 on the port in the backend HTTP setting and return 200

Cause

### Backend request time-out is exceeded

First check

The time-out on the backend HTTP setting

Cause

### Backend pool is not configured or is empty

First check

The pool has VMs or scale set members, with provisioning state `Succeeded`

Cause

### All instances in the pool are unhealthy

First check

Probe results, and whether the app is deployed on the instances

Cause

### The backend certificate does not match the host header

First check

The certificate's DNS name against the host name sent to the backend

Default probe, as documented
| Property | Value |
| Probe URL | `http://127.0.0.1/` |
| Interval | 30 seconds |
| Time-out | 30 seconds |
| Unhealthy threshold | 3 consecutive failures |
Microsoft's checks for NSGs, routes and DNS (Azure PowerShell; needs your resources)

```
Get-AzEffectiveNetworkSecurityGroup -NetworkInterfaceName nic1 -ResourceGroupName testrg Get-AzEffectiveRouteTable -NetworkInterfaceName nic1 -ResourceGroupName testrg Get-AzVirtualNetwork -Name vnetName -ResourceGroupName rgName
```

Test the path from a diagnostic VM to the backend port (needs Azure CLI and your resources)

```
az network watcher test-connectivity \ --source-resource '<diagnostic-vm-resource-id>' \ --dest-address '<backend-ip-or-fqdn>' \ --protocol TCP \ --dest-port '<backend-port>'
```

I confirmed these `az` commands and their flags exist in the installed Azure CLI help, and took the PowerShell and the output interpretation from the Microsoft article; none were run against a subscription.

_04_Your call

## Application Gateway: a time-out is a 502 on v1 and a 504 on v2

Microsoft says the gateway waits a configurable interval for the backend, 20 seconds by default. On Application Gateway v1 a missed deadline returns a 502. On v2 the request is tried against a second backend pool member, and if that also fails, the user gets a 504 instead. So a v2 gateway returning 502 is less likely to be a plain time-out, and you should look at the probes and certificate rows above.

If this fits

### Raise the time-out when

- The slow request is a known report or long query
- The backend is healthy and its response time is stable
- You can name the longest legitimate request

Or

### Fix the backend when

- Response time tracks CPU or memory pressure
- A database or query is the slow part
- The failures grow with traffic

Raise the request time-out on a backend HTTP setting (needs your gateway)

```
az network application-gateway http-settings update \ --gateway-name <application-gateway-name> \ --resource-group <resource-group-name> \ --name <backend-http-settings-name> \ --timeout <time-out-in-seconds>
```

**The accepted range**The Microsoft article gives the request time-out range as 1 to 86400 seconds on the backend HTTP setting. Because it is a property of the setting, different backend pools can have different values.

_05_How it works

## App Service: observe, collect, mitigate

Microsoft's App Service 502 and 503 guide says these errors often come from an application-level problem: requests taking a long time, high memory or CPU use, or an exception that stops the app responding. The steps run in order. Open Monitoring and then Metrics to look at memory working set, CPU time and requests. Then collect data with Diagnose and solve problems, or the Kudu console under Development Tools and then Advanced Tools, which offers a log stream and a diagnostic dump.

1. 01

### Check metrics first

In the app's Monitoring, then Metrics, add Average memory working set, CPU time, Memory working set and Requests, and look for a spike that lines up with the 502s.
2. 02

### Use Diagnose and solve problems

Microsoft describes it as a no-configuration experience that can discover a problem and guide you to the right information.
3. 03

### Scale or add instances

Moving to a higher tier or running more than one instance adds capacity, and if the process goes down on one instance the other keeps serving.
4. 04

### Consider auto-healing

Auto-healing recycles the worker process based on triggers you add to the root `Web.config`, such as memory limits, request counts or request duration. Microsoft says these settings work the same even if the app is not .NET.

_06_Explained

## What an Azure 502 means for SEO

[Googlebot](/ai-crawlers/googlebot) meets an Azure 502 as one more server error, and Google's [status code](/glossary/http-status-codes) guide says the crawler eases off when 5xx responses appear. Pages that are already indexed stay for a while but can drop out if the failures do not stop. Which pages suffer depends on the cause: a failed probe empties the whole pool, so every URL behind it fails, while a time-out hits only the slow endpoints. Count affected URLs in your logs to see which you have. See [5xx server errors](/seo-issues/server-errors-5xx) and the generic [502 Bad Gateway](/errors/http/502) page.

Questions

## Asked a lot.

3 questions people ask next, answered from the sources on this page.

_01_ What is the default Application Gateway backend time-out?

20 seconds, according to Microsoft's troubleshooting article. The request time-out is a property of the backend HTTP setting and accepts 1 to 86400 seconds.

_02_ Why does Application Gateway v2 return 504 where v1 returned 502?

On v2, when the backend does not answer in the interval, the gateway retries a second backend pool member. If that also fails the user gets a 504. On v1 the user request gets a 502 directly.

_03_ Is a 502 from Azure App Service my app's fault?

Often. Microsoft lists slow requests, high memory or CPU use, and unhandled exceptions as the usual causes. Check metrics and the Kudu log stream before changing gateway settings.

Sources · 4

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- microsoft.com
- google.com

1. 01 [Microsoft Learn: Troubleshoot bad gateway (502) errors in Azure Application Gateway](https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-troubleshooting-502) learn.microsoft.com · checked 2026-11-01
2. 02 [Microsoft Learn: Troubleshoot HTTP 502 and HTTP 503 errors in Azure App Service](https://learn.microsoft.com/en-us/troubleshoot/azure/app-service/troubleshoot-http-502-http-503) learn.microsoft.com · checked 2026-11-01
3. 03 [Microsoft Learn: Troubleshoot common Azure Front Door issues](https://learn.microsoft.com/en-us/azure/frontdoor/troubleshoot-issues) learn.microsoft.com · checked 2026-11-01
4. 04 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-11-01

## Keep learning

[All errors](/errors)

[Learn Azure Front Door 502 CDN and hosting errors](/errors/cdn/azure-front-door-502) [Related 5xx server errors Status codes and links](/seo-issues/server-errors-5xx) [Read next 502 Bad Gateway HTTP status codes](/errors/http/502) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 502 errors
[502 Bad Gateway](/errors/http/502) [502 Bad Gateway in Apache](/errors/http/502/apache) [502 Bad Gateway in nginx](/errors/http/502/nginx) [502 Bad Gateway on Cloudflare](/errors/http/502/cloudflare) [AWS 502 Bad Gateway](/errors/cdn/aws-502-bad-gateway)

More in 502 Bad Gateway
[502 Bad Gateway in Apache](/errors/http/502/apache) [502 Bad Gateway in nginx](/errors/http/502/nginx) [502 Bad Gateway on Azure](/errors/http/502/azure) [502 Bad Gateway on Cloudflare](/errors/http/502/cloudflare)

Terms on this page
[HTTPS](/glossary/https) [HTTP status codes](/glossary/http-status-codes)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
