PROXY protocol boundaries
A connection preamble, not an HTTP header
A TCP load balancer may forward an encrypted or cleartext connection without reading HTTP. The PROXY protocol can carry endpoint information before the application data. Version 1 uses a textual preamble; version 2 uses binary framing and can carry additional typed metadata. Receiving support for v2 was added to Nginx Open Source in 1.13.11. A PROXY preamble does not encrypt data or authenticate the sender. Only a network-restricted, explicitly trusted load balancer should reach a production receiver. Ordinary clients must use a separate listener without this framing requirement.
TCP connection -> PROXY metadata from authorized balancer -> TLS handshake -> HTTP requests inside TLSConfigure reception and identity independently
Enabling proxy_protocol on listen requires the peer to send the expected preamble. It does not by itself replace $remote_addr. For HTTP, use Real IP with real_ip_header proxy_protocol and a narrow trust list. $proxy_protocol_addr represents the reported address, not necessarily a verified identity. The following is an illustrative listener for a privately routed origin; enforce the actual sender restriction at the network boundary. The trusted address is a documentation placeholder.
server { listen 127.0.0.1:19093 proxy_protocol; set_real_ip_from 127.0.0.2; real_ip_header proxy_protocol; location / { root html; }}Distinguish stream reception from transmission
The stream subsystem operates on transport sessions and has its own optional Real IP module. A stream listener can receive PROXY metadata and use set_real_ip_from without the HTTP real_ip_header directive. For sending metadata to another TCP server, stream proxy_protocol on is a separate outgoing setting. Verify the destination accepts the protocol before enabling it. An HTTP reverse proxy does not use this stream directive to send arbitrary upstream metadata. The fragment below assumes the stream module is available and the local upstream explicitly supports PROXY framing.
server { listen 127.0.0.1:19094 proxy_protocol; set_real_ip_from 127.0.0.2; proxy_protocol on; proxy_pass 127.0.0.1:19095;}Diagnose compatibility without weakening trust
If an ordinary HTTP client connects to a PROXY-only listener, HTTP bytes are interpreted as the wrong initial framing and the connection is normally rejected or closed. A framed connection to an ordinary HTTP listener is also incompatible. For TLS the framing must precede the handshake. Confirm the sender configuration, the destination port, the accepted protocol version and network ACL before changing any policy. When a trusted sender is unavailable, use a separate local direct listener rather than broadening the production trust list.
Ordinary HTTP -> ordinary HTTP listener: compatiblePROXY + HTTP -> PROXY-enabled HTTP listener: compatibleOrdinary HTTP -> PROXY-enabled listener: incompatiblePROXY + HTTP -> ordinary listener: incompatiblePractice and next steps
Practice: review a fictional TCP balancer and TLS origin. Explain which listener requires the preamble, which peer may assert addresses and how to verify both valid and invalid pairings. A valid preamble alone is not authorization.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
PROXY protocol boundaries
Explain PROXY protocol framing, match the sender and listener, and distinguish transport metadata from HTTP headers.
Where is PROXY metadata on a TLS-over-TCP connection?
Which framing uses binary encoding?
What does listen ... proxy_protocol require?
Which separate stream setting sends PROXY metadata to an upstream?
Why restrict access to a PROXY-enabled listener?