A proxy chain is a setup where the client's traffic reaches the target through two or more proxies in a row instead of a single one. Over HTTP, each hop opens a CONNECT tunnel to the next. Over SOCKS, the connections are set up one after another. The most common reason is a corporate network that only lets traffic out through its own proxy. The cost comes in two forms: latency adds up, and it gets harder to tell which hop an error came from. This post covers the two ways to build a chain, when you need one, and how to find the hop that broke.
Two ways to build a chain
A chain is built either in the proxy's configuration or in the client's code. The first is called the upstream proxy (or parent proxy) setup. The client only knows the first proxy. The first proxy hands each incoming request to the upstream proxy set in its configuration.
RFC 9110 defines this behavior explicitly. A proxy that receives CONNECT can build the tunnel by connecting to the target directly or by forwarding the request to the next proxy. If you run a proxy, this setting is a single line. In Squid it is a cache_peer … parent line, and we walk through the setup step by step in our Squid post.
In the second setup, the client builds the chain. It first asks A for a tunnel to B, then asks B, through the same connection, for a second tunnel to the target. In our local test, the logs of the two setups looked different:
| Property | Upstream proxy setup | Client's nested tunnel |
|---|---|---|
| Client connects to | A only | A, then B through A |
| Where B's password lives | In A's configuration | In the client |
| What A's log shows | Target: example.com:443 | Only B's address |
| Who builds it | Proxy administrator | Application code |
On a corporate network, the upstream proxy setup is cleaner. The commercial proxy password stays on a single server and is not handed out to clients. If you don't manage the corporate proxy, ask the IT team for this setting.
Nested CONNECT
In a nested tunnel, the client sends two CONNECT requests over the same TCP connection. The first goes to A and asks for B's address. Once A returns 200, the connection is a blind pipe reaching B. The second CONNECT passes through that pipe, reaches B and asks for the target.
Credentials in each request belong to that hop. B's Proxy-Authorization header goes into the second request. A never sees it, because to A the second request is just bytes flowing through the tunnel. The TLS handshake happens last, with the target, inside both tunnels.
curl does not chain two HTTP proxies in one command. The Python example below opens both tunnels by hand and uses only the standard library:
import base64
import socket
import ssl
CORP = ("10.0.0.5", 3128) # hop 1: corporate proxy (example address)
PROXYNET = "pr.proxynet.io:8000" # hop 2
AUTH = base64.b64encode(b"user:pass").decode()
TARGET = "example.com"
def open_tunnel(sock, target, auth=None):
request = f"CONNECT {target} HTTP/1.1\r\nHost: {target}\r\n"
if auth:
request += f"Proxy-Authorization: Basic {auth}\r\n"
sock.sendall((request + "\r\n").encode())
response = b""
while b"\r\n\r\n" not in response:
chunk = sock.recv(4096)
if not chunk:
raise SystemExit(f"connection closed: {target}")
response += chunk
line = response.split(b"\r\n")[0].decode()
print(target, "->", line)
if line.split()[1] != "200":
raise SystemExit(f"chain broken: {target}")
sock = socket.create_connection(CORP, timeout=15)
open_tunnel(sock, PROXYNET) # A opens a tunnel to B
open_tunnel(sock, f"{TARGET}:443", AUTH) # B opens a tunnel to the target
tls = ssl.create_default_context().wrap_socket(sock, server_hostname=TARGET)
tls.sendall(f"HEAD / HTTP/1.1\r\nHost: {TARGET}\r\nConnection: close\r\n\r\n".encode())
print(tls.recv(4096).split(b"\r\n")[0].decode())In the test where both hops were local Node proxies, the output was:
127.0.0.1:18001 -> HTTP/1.1 200 Connection Established
example.com:443 -> HTTP/1.1 200 Connection Established
HTTP/1.1 200 OKThe code prints each hop's response separately. If the chain breaks, the output shows which CONNECT it broke at. If the corporate proxy requires NTLM or Kerberos authentication, this short code is not enough. In that case the upstream proxy setup is more practical.
Chaining with SOCKS
A SOCKS chain is built in the same order. The client asks the first SOCKS server for a connection to the second hop's address. Once that connection is up, it runs the handshake with the second hop inside it. Each hop only sees the address of the next one.
curl's --preproxy option builds the most common form of this chain in one command. According to the curl docs, the option puts a SOCKS server in front of an HTTP or HTTPS proxy:
curl --preproxy socks5h://10.0.0.5:1080 \
--proxy http://user:pass@pr.proxynet.io:8000 \
https://example.comIn our test, the SOCKS server's log contained only the second hop's address. The second hop saw the CONNECT example.com:443 request. With socks5h, the SOCKS server resolves the second hop's name, and the HTTP proxy resolves the target's name. The client resolves no name with its own DNS.
Proxynet offers both protocols: HTTP and SOCKS5 Proxy. Your client tool decides the order in which the chain is built.
When you need a chain
You need a chain when the network won't let you out through a single proxy. In practice, three cases come up:
- Mandatory corporate egress proxy. The corporate network reaches the internet only through its own proxy. To reach a commercial proxy, that proxy becomes the first hop. Set this up with the IT team's knowledge and approval.
- Servers on a closed network. A server with no direct internet access goes out through a single relay machine on the same network. The relay machine can also sit in another region.
- A single exit point. Everyone on the team connects to a local forwarder, and the forwarder hands the traffic to the commercial proxy. The password lives in one place.
The last hop is usually a commercial exit such as Residential Proxy. The target site only sees the last hop's IP. An extra hop does not change that.
Don't treat a chain as a privacy layer. Its purpose is to fit a network constraint, and every hop keeps its own log. If a single proxy does the job, don't build a chain.
The cost of a chain
The first cost of a chain is latency. Every message passes through all hops, so every round trip pays the sum of the latencies between the hops. During connection setup this repeats several times: TCP, two CONNECT requests and the TLS handshake. We explain where latency comes from in What Is Latency?.
That is why the geography of the hops matters. Traffic going from an office in Istanbul to a relay server in Frankfurt, then back to an exit in Türkiye, travels the distance twice. Pick hops that are close to each other.
The second cost is authentication. Each hop asks for its own password, and each one is a separate source of 407 errors. The third is port restrictions. RFC 9110 recommends that proxies limit CONNECT to known ports. That is why many corporate proxies only open tunnels to 443 and reject a CONNECT to a port like pr.proxynet.io:8000. The upstream proxy setup avoids this problem, because the corporate proxy opens the connection to the upstream proxy through its own configuration.
The last cost is debugging. With a single proxy, the error is either in the proxy or at the target. In a chain, the same error code can come from three different places.
Finding the broken hop
The way to find the broken hop is to read who the error came from. With -v, curl shows each CONNECT response on its own line. In our test we broke each hop one at a time, and curl 8.23.0 gave these outputs:
| Output | Broken hop | Meaning |
|---|---|---|
(7) Failed to connect … over proxy | First hop | The SOCKS preproxy is unreachable |
(97) cannot complete SOCKS5 connection … (5) | SOCKS → second hop | The SOCKS server could not reach the second proxy |
(7) CONNECT tunnel failed, response 407 | Whichever hop sent Proxy-Authenticate | That hop's password is wrong |
(7) CONNECT tunnel failed, response 502 | Between the first hop and the upstream proxy | The first proxy could not reach the upstream proxy |
The 5 in the (97) line is the SOCKS reply code from RFC 1928 and means "connection refused". With 407, you need to tell which of the two hops asked for the password. The forwarder in our test passed the upstream proxy's 407 response through unchanged. The realm value in the Proxy-Authenticate header showed that the hop asking for the password was the upstream proxy. We cover diagnosing the password side in detail in our HTTP 407 error post.
Three checks solve most cases:
- Test each hop on its own. If you can reach B without the chain, the problem is between A and B.
- Check the log of the hop you control. If the request never arrived there, the problem is earlier in the chain.
- Set timeouts for the chain. A connect timeout chosen for a single proxy may not be enough for two hops.
How we tested
We ran the test on December 1, 2026, on Windows 11. The hops were local proxies written with Node 24.22.2: an HTTP proxy that requires a password, an HTTP proxy without one, a forwarder that hands requests to an upstream proxy, and a SOCKS5 server without a password. Every proxy logged the incoming request. The clients were Python 3.13 and curl 8.23.0, and the target was https://example.com. We got the error lines by shutting down each hop one at a time or by giving a wrong password.
The bottom line
Use a chain only when the network forces you to. On a corporate network, choose the upstream proxy setup, and build a nested tunnel in the client only if you have no access to the proxy settings. Above all, test each hop on its own: in a chain, an error code does not tell you where it came from.
Sources
- RFC 9110, Section 9.3.6: CONNECT: rfc-editor.org
- RFC 1928: SOCKS Protocol Version 5: rfc-editor.org
- curl man page, --preproxy: curl.se
Frequently asked questions
Does a proxy chain increase anonymity?
No, a chain is not designed as an anonymity tool. In every case, the target site only sees the last hop's IP. Extra hops don't change that; they only add places the traffic passes through. Every hop keeps its own log. The legitimate purpose of a chain is to fit a network constraint, for example reaching a commercial proxy from behind a corporate mandatory egress proxy.
Are an upstream proxy and a parent proxy the same thing?
Yes. Both describe the next proxy that a proxy hands a request to instead of connecting to the target itself. In this setup the client only knows the first proxy, and the commercial proxy password lives in the first proxy's configuration. On corporate networks, it is the cleanest way to keep the password in one place.
Can curl use two HTTP proxies in a row?
Not in one command. curl's --preproxy option only puts a SOCKS server in front of an HTTP or HTTPS proxy. For two HTTP proxies, you either set an upstream proxy on the first proxy or build the nested CONNECT requests in code. The Python example in this post shows the second approach with the standard library.
How do I tell which hop in the chain returned 407?
Look at the Proxy-Authenticate header in the curl -v output. The realm value in that header often names the proxy asking for the password. If you build a nested tunnel, print each CONNECT response separately: the first response comes from A, the second from B. That is why the Python code in this post prints responses hop by hop.
How much latency does a proxy chain add?
The sum of the latencies between the hops. Every message passes through all hops, so every round trip pays that sum. During connection setup, TCP, two CONNECT requests and the TLS handshake run one after another, so the difference is most noticeable on the first request. Picking hops that are geographically close to each other keeps the difference small.
What should I do if the corporate proxy rejects CONNECT to port 8000?
Ask the IT team for an upstream proxy setting. Many corporate proxies only open tunnels to well-known ports such as 443, and RFC 9110 recommends this limit too. In the upstream proxy setup, the corporate proxy opens the connection to the commercial proxy through its own configuration. The client's CONNECT request still goes to the target on 443, and the rule stays intact.




