Skip to content
HTTP errors in web scraping and automation · error message

HTTP: 502 Bad Gateway

RetryableHTTP 502Server-side failures (500, 502, 503, 504)

Last verified

The exact message
502 Bad Gateway

What it means

502 means a gateway or proxy in front of the site (a load balancer, CDN or reverse proxy such as nginx) received an invalid response from the upstream server it forwarded your request to. The request reached the site's infrastructure; the application behind it failed to answer correctly.

For automation, 502s cluster during deploys, when upstream processes crash or restart, and when heavy requests kill a worker. If a script hammers expensive pages, it can contribute to the overload that produces 502 for everyone. Cloudflare-fronted sites report the same family of problems with their own codes such as 520.

What is not wrong: your network and your request format, usually.

What it looks like

<html><head><title>502 Bad Gateway</title></head>
<body><center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center></body></html>

Why it happens

  • The upstream application crashed, restarted or closed the connection mid-response.
  • A deploy or scaling event briefly left the load balancer without healthy backends.
  • The upstream sent a malformed response (bad headers, protocol mismatch).
  • Overload from high request volume.

How to fix it

  1. Retry after a short delay with exponential backoff.
  2. Reduce your concurrency against that host.
  3. Check the site's status page or recent announcements.
  4. If you own the site, check the proxy's error log and the upstream application's logs at the same timestamp.
  5. If 502s persist for hours on one host, pause the job and alert a person rather than retrying indefinitely.

How to stop it recurring

Treat 502 as retryable with backoff, keep concurrency low, and schedule large jobs off-peak so your traffic never contributes to the overload. Record the time and URL of each 502 so you can tell a one-off deploy blip from a pattern. If you operate the site, health checks, connection draining and graceful restarts prevent most deploy-time 502s.

Official documentation: developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/502. See all HTTP error messages.

Related errors

Definitions

Quick answers

What does "502 Bad Gateway" mean in HTTP?

502 means a gateway or proxy in front of the site (a load balancer, CDN or reverse proxy such as nginx) received an invalid response from the upstream server it forwarded your request to. The request reached the site's infrastructure; the application behind it failed to answer correctly. For automation, 502s cluster during deploys, when upstream processes crash or restart, and when heavy requests kill a worker.

How do I fix "502 Bad Gateway"?

1. Retry after a short delay with exponential backoff. 2. Reduce your concurrency against that host. 3. Check the site's status page or recent announcements. 4. If you own the site, check the proxy's error log and the upstream application's logs at the same timestamp. 5. If 502s persist for hours on one host, pause the job and alert a person rather than retrying indefinitely.

Retries and timeouts without writing the loop

Autonoly's HTTP Request node and browser steps have per-node retries, timeouts and continue-on-fail, so a transient 429 or 503 can back off instead of failing the run. It has no proxies or IP rotation: if a site blocks automated traffic, that block applies to Autonoly too.

Also see Error handling in workflows.