What Is a Forward Proxy? How It Works
In many companies, your laptop does not connect to websites directly. Every outgoing request first goes to a forward proxy, which decides whether it is allowed and then makes the request for you.
Forward proxies control and protect outbound traffic. Cloud platforms also use them so that servers can call external APIs from one known IP address. This tutorial explains how they work, how HTTPS passes through them, and how to configure and use one.
1. What Is a Forward Proxy?
A forward proxy is a server that sits between a group of clients and the internet and sends requests to external servers on the clients' behalf. The external server sees the proxy's IP address, not the client's.
Clients are configured to use it, through browser settings, environment variables such as HTTPS_PROXY, or a PAC file. The proxy can also be "transparent" and intercept traffic at the network level. Types of Proxy Servers covers that variant.
2. Forward Proxy Architecture
All outbound traffic leaves through one controlled point. The company can apply policy, keep audit logs, and give external services a single IP address to allow-list.
3. How a Forward Proxy Works
Plain HTTP
The client sends the full URL to the proxy, for example GET http://news.example.org/today HTTP/1.1. The proxy checks the policy, opens its own connection to the site, forwards the request and returns the response. It can cache the response for other users.
HTTPS with the CONNECT method
- The client asks the proxy to open a tunnel:
CONNECT news.example.org:443 HTTP/1.1. - The proxy checks whether that host and port are allowed, connects to the site, and replies
200 Connection Established. - The client performs the TLS handshake with the website through the tunnel. The proxy relays the encrypted bytes but cannot read them.
- The proxy still sees the destination hostname and how much data moves, which is enough for allow lists and logging.
4. Key Functions of a Forward Proxy
- Access control: allow or block sites and categories per user or group.
- Egress control for servers: backend services reach only approved external APIs.
- Caching: popular downloads, such as software packages, are fetched once and shared.
- Privacy and IP masking: external sites see the proxy's address.
- Auditing: central logs of who accessed which host and when.
- Fixed outbound IP: partners can allow-list a single IP address.
5. Practical Implementation
Squid forward proxy
Squid is a widely used open-source forward proxy. This configuration lets only the internal network use the proxy, allows HTTPS tunnels only to port 443, and blocks a list of domains.
http_port 3128
acl localnet src 10.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 443
acl CONNECT method CONNECT
acl blocked_sites dstdomain .blocked.example .malware.example
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny blocked_sites
http_access allow localnet
http_access deny all
cache_dir ufs /var/spool/squid 2048 16 256
Using the proxy from Java
Java's built-in HttpClient sends requests through a proxy with one builder call. HTTPS URLs automatically use the CONNECT tunnel.
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ProxySelector;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
public class ProxyClient {
public static void main(String[] args) throws IOException, InterruptedException {
HttpClient client = HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress("proxy.internal", 3128)))
.connectTimeout(Duration.ofSeconds(5))
.build();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://news.example.org/today"))
.timeout(Duration.ofSeconds(10))
.GET()
.build();
// HTTPS: the client sends CONNECT news.example.org:443 to the proxy, then TLS runs inside the tunnel
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status: " + response.statusCode());
}
}
This class compiles on Java 17 and 21. Running it needs a proxy listening at proxy.internal:3128. For command-line tools, set HTTPS_PROXY=http://proxy.internal:3128 instead.
6. Advantages and Disadvantages
Advantages
- Central control and logging of outbound traffic.
- Hides internal client addresses.
- Saves bandwidth through shared caching.
- Gives external partners one IP address to trust.
Disadvantages
- Adds latency and becomes a bottleneck if undersized.
- A single proxy is a single point of failure.
- Cannot inspect HTTPS content without TLS inspection.
- Clients must be configured, or traffic must be intercepted transparently.
7. Forward Proxy Compared
| Aspect | Forward proxy | Reverse proxy | VPN |
|---|---|---|---|
| Acts for | Clients | Servers | A whole device or network |
| Position | Near the clients | In front of servers | Between device and remote network |
| Traffic covered | Apps configured to use it | Requests to the servers it fronts | All traffic routed into the tunnel |
| Encryption | Not by itself (HTTPS stays end to end) | Terminates TLS for servers | Encrypts the whole tunnel |
See Forward Proxy vs Reverse Proxy and Forward Proxy vs VPN for details.
8. Real-World Use Cases
- Corporate networks: web filtering, malware blocking and compliance logging for employees.
- Cloud egress: microservices in a private subnet call payment or email APIs through an egress proxy with an allow list.
- Build servers: a caching proxy for Maven or npm packages speeds up builds and survives upstream outages.
- Schools and public Wi-Fi: content filtering for age-appropriate access.
Large organisations often distribute proxy settings with a Proxy Auto-Configuration (PAC) file: a small JavaScript function that tells the browser which proxy to use for each URL. Internal sites can go direct while internet traffic goes through the proxy, and the rules change centrally without touching every device.
9. Best Practices
- Deny by default: allow only known networks and destinations, and restrict CONNECT to port 443.
- Authenticate users when you need per-user policy and audit trails.
- Run it redundantly: at least two instances behind one name, sized for peak traffic.
- Protect logs: access logs contain browsing history; apply retention limits and access control.
- Never run an open proxy: an internet-reachable proxy without access rules will be abused quickly.
- Be transparent about TLS inspection and exclude sensitive categories such as banking and health.
10. Summary
- A forward proxy sends requests to the internet on behalf of clients.
- Websites see the proxy's IP, not the client's.
- HTTPS goes through a CONNECT tunnel, so the proxy sees the host but not the content.
- Common uses: filtering, egress control, caching, auditing and fixed outbound IPs.
- Squid is a popular forward proxy; Java's
HttpClientsupports proxies natively.
Next, compare all proxy variants in Types of Proxy Servers.
Forward Proxy: Top Interview Questions
These are the forward proxy questions most often asked in system design interviews, with short answers you can explain in your own words.
Q1. What is a forward proxy?
A server that makes requests to the internet on behalf of clients. The destination sees the proxy's IP address, and the organisation can control, cache and log outbound traffic in one place.
Q2. How does a forward proxy handle HTTPS?
The client sends CONNECT host:443. The proxy opens a TCP tunnel to that host, and the client does the TLS handshake through it. The proxy sees the hostname but not the encrypted content, unless TLS inspection is configured.
Q3. Why would backend servers use a forward proxy?
For egress control: services can reach only approved external APIs, all outbound calls are logged, and partners see one fixed IP address they can allow-list.
Q4. What is an open proxy and why is it dangerous?
A proxy that anyone on the internet can use. Attackers use open proxies to hide their identity for spam, fraud and attacks, and the proxy owner's IP gets blocked. Always restrict access by network or authentication.