Free auditStart free
GuideError · HTTP status codes

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.

5 min
read
4
sources
Nov 1, 2026
updated
Scaplet Editorial Team
author
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
  2. Check it in 2 minutes
  3. Application Gateway: the six documented causes
  4. Application Gateway: a time-out is a 502 on v1 and a 504 on v2
  5. 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 withChatGPTClaudePerplexityGoogleAI Mode
02Check 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
04Your 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>
05How 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.

06Explained

What an Azure 502 means for SEO

Googlebot meets an Azure 502 as one more server error, and Google's status code 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 and the generic 502 Bad Gateway page.

Questions

Asked a lot.

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

01What 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.

02Why 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.

03Is 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. 01Microsoft Learn: Troubleshoot bad gateway (502) errors in Azure Application Gatewaylearn.microsoft.com · checked 2026-11-01
  2. 02Microsoft Learn: Troubleshoot HTTP 502 and HTTP 503 errors in Azure App Servicelearn.microsoft.com · checked 2026-11-01
  3. 03Microsoft Learn: Troubleshoot common Azure Front Door issueslearn.microsoft.com · checked 2026-11-01
  4. 04How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-11-01
Free · 2 minutes

Tools point. Agencies advise. This one ships.

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

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane