00:00

What Is a Forward Proxy? How It Works

Last updated:

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

Forward proxy architecture Employee laptops inside a company network send all outbound web requests to a forward proxy. The proxy checks the company policy, allows the request to a news site and blocks a request to a blocked site, then sends allowed requests to the internet using its own IP address. COMPANY NETWORK Laptop 1 Laptop 2 Laptop 3 Forward Proxypolicy · cacheoutbound IP INTERNET news.example.orgallowed blocked.exampleblocked by policy
A forward proxy stands in front of the clients. Websites see the proxy's IP address, not the users'.

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

  1. The client asks the proxy to open a tunnel: CONNECT news.example.org:443 HTTP/1.1.
  2. The proxy checks whether that host and port are allowed, connects to the site, and replies 200 Connection Established.
  3. The client performs the TLS handshake with the website through the tunnel. The proxy relays the encrypted bytes but cannot read them.
  4. The proxy still sees the destination hostname and how much data moves, which is enough for allow lists and logging.
Note: Some corporate proxies decrypt HTTPS by installing their own certificate authority on company devices. This is called TLS inspection. It allows content scanning but raises privacy and security concerns, and it must be clearly disclosed.

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.

squid.conf
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.

ProxyClient.java
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

AspectForward proxyReverse proxyVPN
Acts forClientsServersA whole device or network
PositionNear the clientsIn front of serversBetween device and remote network
Traffic coveredApps configured to use itRequests to the servers it frontsAll traffic routed into the tunnel
EncryptionNot by itself (HTTPS stays end to end)Terminates TLS for serversEncrypts 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 HttpClient supports proxies natively.

Next, compare all proxy variants in Types of Proxy Servers.