A proxy port is the number that tells your software which service on a proxy server to connect to. It is written after the host and a colon, as in proxy.example.com:8080. The host finds the server, and the port picks the service on it. Both must be correct, or the connection fails or reaches the wrong service.
A port is a 16-bit number, so it can't be larger than 65535. The proxy port only covers the hop from your device to the proxy. The site you request has its own port, and the two are set in different places.
How a Proxy Port Works
- Your client connects: it opens a TCP connection to the proxy's host and port.
- It speaks the port's protocol: an HTTP proxy port expects HTTP requests, and a SOCKS port expects the SOCKS handshake.
- It names the target: for an HTTPS site through an HTTP proxy, the client sends a
CONNECTrequest whose target is only the site's host and port, such asexample.com:443. There is no default port, so the client must send one. - The proxy relays: it connects to the target port and passes traffic in both directions.
Common Proxy Port Numbers
- 8080: Registered with IANA as "HTTP Alternate" to port 80.
- 3128: The port the open-source Squid cache normally listens on. IANA registers 3128 to a different service, so the number is a habit, not a rule.
- 1080: Registered with IANA for SOCKS. RFC 1928 states the SOCKS service is conventionally on TCP port 1080.
- 80 and 443: The standard ports for HTTP and HTTPS.
- Port ranges: RFC 6335 splits ports into System Ports (0 to 1023), User Ports (1024 to 49151), and Dynamic Ports (49152 to 65535).
IANA notes that a registered port doesn't mean the traffic on it belongs to that service. Always use the port listed in your proxy details.
Proxy Port vs. Target Port
| Proxy port | Target port | |
|---|---|---|
| What it reaches | The proxy service | The website or API |
| Where you set it | After the proxy host in your proxy settings | In the URL you request, or the CONNECT target |
| Typical values | 8080, 3128, 1080 | 80, 443 |
| Who decides | The proxy operator | The site |
A proxy can also limit which target ports it will tunnel to. MDN advises operators to restrict CONNECT to known ports, and the Squid cache's suggested configuration denies CONNECT to anything outside its SSL ports list, which by default holds only 443. A site on a port like 8443 can fail through such a proxy even when the proxy port is right.
The Scheme Names the Proxy, the Key Names the Site
Proxy settings often carry two schemes that mean different things, and mixing them up is a common cause of traffic skipping the proxy.
- In Python Requests: the
proxiesdictionary key is the scheme of the site you request, and the value is the proxy URL. The docs' own example routeshttpstraffic throughhttp://10.10.1.10:1080. If thehttpskey is missing, HTTPS requests don't use that proxy. Proxy URLs must include the scheme. - In curl: the prefix picks the proxy type. No prefix or
http://means an HTTP proxy,https://an HTTPS proxy, andsocks5://a SOCKS5 proxy. - Where DNS happens: with
socks5h://, the proxy resolves the site's hostname. Withsocks5://, your machine does, which sends the lookup outside the proxy.
Setting the Port in Your Tools
- Command line: curl takes a proxy as
-x [protocol://]host[:port], for examplecurl -x http://proxy.example.com:8080 https://example.com. If you leave out the port, curl assumes 1080, and its docs warn against assuming any single port is used widely for proxies. - Environment variables: curl and Requests both read proxy variables such as
http_proxy,HTTPS_PROXY, andALL_PROXYin the samehost:portformat, and skip the proxy for hosts inNO_PROXY. Requests accepts lowercase and uppercase names.
Reading Port Errors
- Connection refused: the host answered, but nothing is listening on that port, which usually means a wrong port number.
- Timeout: nothing answered within the time limit. Check that the host and port are right and that your network allows outbound traffic to that port.
- Couldn't resolve proxy: the proxy hostname is wrong; the port was never tried.
- 407 response: the port is right and the proxy answered, but it needs valid proxy authentication.
What It Means for Web Scraping
- Match port and protocol: send HTTP to an HTTP proxy port and SOCKS to a SOCKS5 proxy port. The port number alone doesn't tell the client which to use.
- Set both keys: in Requests, give
httpandhttpsthe same proxy URL, then check the exit IP before a long run. - Watch non-standard targets: if HTTPS sites on 443 work but one on another port fails, the proxy may be refusing that
CONNECTtarget.