502 Bad Gateway Error Through a Proxy

An intermediate server did not get a proper response from the next hop. This is usually solved by retrying or changing the address.

Updated · Prokso editorial team

Key takeaways
  • Code 502 means an intermediary got no proper response from the next hop
  • Most often the site is down, overloaded or rejected the connection from this address
  • Retry the request: with rotation, the next one goes through a different address

What the error means

The 502 code means that an intermediary server passed the request on and got an error or nothing at all. The intermediary may be our gateway, or it may be a server in front of the site itself.

In Prokso the gateway response looks like 502 NO_HOST_CONNECTION: the proxy could not connect to the site. If there is no name after the code, the 502 was returned by the site or its content delivery network.

Who returns the error: 407 comes from the proxy, 401 and 403 from the website itselfYour appProxygw.prokso.comWebsite407 - the proxy answers: username, password or traffic left401 / 403 - the website answers: site login or access
Who returns the error: 407 comes from the proxy, 401 and 403 from the website itself

Causes

  • The site is down or overloaded. It does not answer anyone - neither through the proxy nor directly.
  • The site rejected the connection from this address. The same site may answer from another address or another country.
  • An error in the site address. A typo in the domain, a subdomain that does not exist, a wrong port.
  • The protocol is mixed up. An HTTP request was sent to the SOCKS5 port or the other way round.
  • A particular exit address is offline. In residential and mobile networks a device can drop off the network at any moment.

How to fix it

  1. Retry the request: with rotation, the next one will go through a different address.
  2. Check the site address and open it without the proxy - does it work at all?
  3. Check the port and protocol: 823 is HTTP, 824 is SOCKS5.
  4. Change the country or remove the city and ISP targeting.
  5. On a sticky IP, change the session: take another port from the 10000–20000 range.
  6. Add a retry on 502 with a short pause to your program - two or three attempts are enough.

How to check that it works

Test the line in the proxy checker. If the proxy responds and 502 remains on one site only, the cause is on that site's side.

Two-minute diagnosis

First paste the line into the proxy checker. If the proxy works there, the cause is in your app or its settings. If not, test the line from a terminal:

curl -v -x "http://USERNAME:PASSWORD@gw.prokso.com:823" https://api.ipify.org
  • A < HTTP/1.1 407 line right after CONNECT means the proxy answered. The name after the code, for example NO_USER, points to the cause.
  • The proxy answered CONNECT with 200 and then another code arrived - the proxy works, and that answer came from the website.
  • No answer at all, only a timeout - the connection never reached the proxy: check the host, port and network.

Proxy not working? Check it in 6 steps

FAQ

How is 502 different from 503 and 504?

502 - the intermediary got a bad response. 503 - the service is temporarily unavailable or there are no free addresses. 504 - the intermediary did not get a response within the allotted time.

502 shows up from time to time. Is that normal?

Rare single 502 errors are expected for residential and mobile addresses: devices go offline. Retrying the request solves it. If the error repeats in a row for more than a few minutes, contact support.

Where can I see which errors the plan had?

In the dashboard, in the plan's request log: it shows the error code and the time.

What does 502 Bad Gateway mean in plain words?

An intermediary between you and the site - the proxy, a CDN or a server in front of the site - passed the request on and did not get a proper response. The code itself does not say where it failed, so first find out who sent it. The steps are in the proxy check with curl -v.

How do I tell who returned the 502: the proxy or the site?

The Prokso gateway writes the reason after the code: 502 NO_HOST_CONNECTION means the proxy could not connect to the site. If there is no name and the error page is styled by the site or its CDN, the site sent the 502. For https sites the browser does not show the proxy response and replaces it with ERR_TUNNEL_CONNECTION_FAILED, so check with curl -v.

Why do I get 502 on one site only while others open?

Then the proxy works and the problem is that site: it is overloaded, temporarily down or does not accept connections from this address or country. Open it without the proxy. If it works without the proxy, repeat the request through another address (on ports 823 and 824 every request goes out from a new IP) or pick another country. Ports and geo parameters are in the gateway reference.

Residential $1.59, mobile $2.50, datacenter $0.65 per GB

Sign up in a minute, get access right after payment.

Create account

Install the Prokso app