502 Bad Gateway proxy errors: find out who sent it
Updated:
502 Bad Gateway means a server in the middle, which could be your proxy or the website's own front-end server, forwarded the request and did not get a valid answer back. Same number, two very different culprits, so before fixing anything work out who is returning the 502.
What a 502 from the proxy looks like
We made our test proxy answer 502 and recorded the responses, rewritten with 203.0.113.10:8080 and user123:pass456:
- HTTPS site:
curl -x http://user123:[email protected]:8080 https://example.comprintscurl: (56) CONNECT tunnel failed, response 502. - Plain HTTP site: curl receives status
502. - Chrome loading an HTTPS page through that proxy reports
ERR_TUNNEL_CONNECTION_FAILEDand shows no 502 page at all. - The proxy checker shows
HTTP 502; other codes appear the same way asHTTP <code>.
The tell: a 502 page on an HTTPS site
For HTTPS sites the proxy only opens a tunnel; it cannot insert its own page inside an encrypted connection. If the proxy refuses, Chrome reports ERR_TUNNEL_CONNECTION_FAILED. So when you see a full "502 Bad Gateway" page rendered on an https:// address, it almost certainly came from the website's server, not from the proxy.
Confirm by turning the proxy off and loading the same page. If it is still a 502, the website is having trouble and waiting or telling the site owner is all you can do.
When the proxy really is sending the 502
- The destination does not answer the proxy. The site is down, overloaded, or refusing connections from the proxy's IP range.
- A mistyped or unresolvable domain. The proxy cannot find the site's address, so there is nothing to forward to.
- The destination port is closed. The request targets a port the site does not serve.
- A temporary fault on the proxy side. Rarer; you notice it when every site returns 502 through one proxy but works through another.
What to do in each environment
- Chrome or antidetect profiles: open a different large site in the same profile. If that loads, the proxy is fine and the original site is the problem.
- Phones: switch off the Wi-Fi proxy and try the page over mobile data to see whether the site fails for everyone.
- curl: add
-vto see the 502 arrive right afterCONNECT, then repeat with a different domain to narrow it down. - Python requests: for HTTP pages check
response.status_code == 502and retry after a pause; for HTTPS pages the failed tunnel is raised asrequests.exceptions.ProxyError. Space retries out rather than hammering the site.
Step by step
- 1
Note where the 502 appears
A 502 page on an https address points to the website. A tunnel error in Chrome points to the proxy path.
- 2
Turn the proxy off and reload
A 502 without the proxy means the website itself is failing.
- 3
Load another site through the same proxy
If other sites work, the proxy is fine and only the original site is refusing or down.
- 4
Check the proxy with the checker
Paste the line into the proxy checker. If every site gives
HTTP 502, open a ticket with the result.
Frequently asked questions
Does a 502 mean my proxy has expired?
Usually not. An expired or stopped proxy tends to produce a connection failure or a timeout; see proxy timeout.
Why does only one website return 502 through the proxy?
That site may be failing or not answering connections from the proxy's IP. Try later, or use an IP in another country.
What is the difference between 502 and 504?
A 502 means an invalid answer or none could be obtained; a 504 means the middle server waited too long. The checker shows both as HTTP <code>.
My scraper gets occasional 502s. Should I change proxies?
Scattered 502s usually mean an overloaded target. Slow your request rate and add spaced retries before swapping proxies; see proxies for web scraping.
Private IPs, not shared with strangers
VinaProxy private proxies help you avoid an IP being blocked because someone else was using it.
See pricing