HTTP: 502 Bad Gateway
Last verified
502 Bad GatewayWhat 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
- Retry after a short delay with exponential backoff.
- Reduce your concurrency against that host.
- Check the site's status page or recent announcements.
- If you own the site, check the proxy's error log and the upstream application's logs at the same timestamp.
- 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
- CAPTCHACAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a challenge-response m
- Cloudflare Bot ManagementCloudflare Bot Management is the set of Cloudflare features (Bot Fight Mode, Super Bot Fight Mode and the Ente
- DataDomeDataDome is a commercial bot-protection service that scores every request to a website, app or API in real tim
- HUMAN Security (PerimeterX)PerimeterX, now HUMAN Security's Bot Defender after a 2022 merger, is a bot-protection service that scores eve
- User AgentA user agent is a string that browsers send with every HTTP request identifying the browser type, version, and
- AI Web ScraperAn AI web scraper is an AI-powered data extraction tool that understands page structure, identifies relevant d
- Data ScrapingData scraping is the broad practice of programmatically extracting data from any digital source — websites, ap
- Web CrawlerA web crawler (also called a spider or bot) is a program that systematically browses the internet by following
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.