Sub topic 2
How a Proxy Relays HTTP and HTTPS Traffic
Assume you understand HTTP methods and headers, IP addresses, ports, DNS, and the purpose of TLS. A proxy is an intermediary that receives traffic and sends it onward. The client may connect to a forward proxy, or the server may be hidden behind a reverse proxy.
HTTP and HTTPS relay mechanics
For HTTP, a client sends a request to the proxy. The proxy selects a destination, opens a connection, forwards the request, and returns the response.
For HTTPS, an explicit forward proxy usually receives a CONNECT request. The proxy opens a TCP connection to the requested host and port, then relays encrypted bytes. TLS runs between the client and the destination, so the proxy cannot read the HTTP content.
A reverse proxy often terminates TLS itself. It decrypts the request, then sends HTTP or HTTPS to a backend. Forwarding headers preserve information about the original request.
Access control and egress filtering
A forward proxy can control outbound traffic. An access control rule can restrict which client networks may connect and which destination domains they may reach. This creates egress control, which limits where internal systems can send requests.
http_port 3128
acl localnet src 10.0.0.0/8
acl allowed_sites dstdomain .example.org
http_access allow localnet allowed_sites
http_access deny allKeep proxy access rules narrow. Otherwise, the proxy can become an open relay that attackers use to reach private networks or hide abusive traffic.
Explicit and transparent deployments
In an explicit deployment, clients know the proxy address through configuration, environment variables, or a discovery protocol. This is easier to audit and usually preserves clear ownership.
In a transparent deployment, network equipment intercepts traffic and redirects it to the proxy. Clients need no configuration, but troubleshooting and HTTPS handling become harder. Interception may also violate user expectations or application assumptions.
Load balancing behind a reverse proxy
A reverse proxy can distribute requests among several backends. Round-robin selection is simple, but session state may require shared storage or session affinity.
upstream app_servers {
server 10.0.0.11:8080;
server 10.0.0.12:8080;
}
server {
listen 80;
location / {
proxy_pass http://app_servers;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Detecting failed backends
A proxy can detect failure through active health checks or failed request attempts. It should stop selecting an unhealthy backend, then retry it after a delay. Health checks must test useful application behavior, not only whether a port accepts connections.
Exercise
For HTTPS through a forward proxy, which endpoint normally performs the TLS handshake?
Show answer
The client and the destination server. The proxy normally relays a CONNECT tunnel and encrypted bytes.