How to Preserve the Real Client IP with the PROXY Protocol

●1 ●29 ●125
calendar_today • schedule4 min read

Losing the real client IP usually shows up as a mystery rather than an error. You place a WAF in front of an app, route traffic through a cloud or on-prem load balancer, and the WAF reports that every visitor comes from the same RFC 1918 address. Rate limits collapse many users into one client, and attack logs point at the balancer instead of the attacker. The fix is often the PROXY protocol, but only when every hop is configured consistently.

The concrete misconfiguration is a half-configured PROXY protocol chain. The PROXY protocol prepends a short header, human-readable in v1 and binary in v2, that carries the original source address, destination address, and ports. The device that terminates the TCP connection, such as a load balancer or CDN, sends the header, and the next hop, such as a WAF, reads it. In the most common failure, the load balancer sends a PROXY v1 header but the WAF listener is still plain HTTP. The WAF treats the bytes 'PROXY TCP4 203.0.113.7 ...' as the start of the request line. Logs show a 400-level error or an invalid request method, and the site fails for every visitor. The mirror case is just as confusing: the WAF expects a PROXY header, but the balancer sends none, so the WAF consumes the first bytes of a normal HTTP request as if they were the header.

SafeLine is documented as a self-hosted WAF that acts as an HTTP/HTTPS reverse proxy, receiving traffic for the original website, filtering malicious traffic, and forwarding safe traffic to the upstream (https://docs.waf.chaitin.com/en/GetStarted/AddApplication). Its listed core capabilities include IP-based rate limiting and a web access control list (https://docs.waf.chaitin.com/en/home), both of which depend on seeing an accurate client address. The deployment guide explains how an application is added with Domain, Port, and Upstream settings (https://docs.waf.chaitin.com/en/GetStarted/AddApplication). Those fields define the listener and forwarding target, not the wire protocol in front of the WAF. The official materials do not describe a PROXY protocol toggle, so treat support as something to verify in your specific setup rather than assume.

A clean fix follows a short checklist. Identify the hop that terminates TCP; it must send the header. Enable PROXY protocol on the load balancer egress and on the WAF ingress in the same operation, because enabling only one side breaks parsing. If the WAF forwards to an origin behind another proxy, repeat that pairing for the next hop. Keep v1 and v2 consistent, since both sides must agree. Finally, confirm with a log line before trusting the change.

Why do my WAF logs show the load balancer IP instead of real users?

A WAF logs the address of its direct peer. When a load balancer or CDN sits in front, the direct peer is the balancer. Without a mechanism to carry the original address, the WAF cannot reconstruct it, so rate limits and access control keyed on IP see one shared address instead of many users.

Does SafeLine preserve the real client IP through the PROXY protocol automatically?

That is not something the supplied documentation states. The docs describe SafeLine as an nginx-based reverse proxy that receives traffic for the original site and forwards it upstream (https://docs.waf.chaitin.com/en/GetStarted/AddApplication), and they list IP-based rate limiting among its capabilities (https://docs.waf.chaitin.com/en/home). They do not document a PROXY protocol setting, so do not assume it is on by default or that a specific version behaves a certain way. Verify in your environment: enable the balancer side and the WAF side together, then read the logs.

What is the difference between PROXY protocol and X-Forwarded-For?

The PROXY protocol works at the TCP layer before any HTTP request is parsed. It survives non-HTTP traffic and cannot be trivially inserted by an end client when only trusted hops are allowed to write it. X-Forwarded-For is an HTTP header that a client can spoof unless the edge rewrites or sanitizes it. Use the PROXY protocol when the immediate hop is a trusted TCP terminator; use X-Forwarded-For only when the chain is HTTP end to end and the header is rewritten at the edge.

What does the fix look like in a log?

Before the change, a sample access log entry shows the balancer address as the remote client:
10.0.0.5 - - [05/Nov/2026:10:00:00 +0800] 'GET / HTTP/1.1' 200 512
After both sides agree on the PROXY protocol, the same request logs the real address:
203.0.113.7 - - [05/Nov/2026:10:00:01 +0800] 'GET / HTTP/1.1' 200 512
The 400 errors from the half-configured state also stop. If the balancer IP still appears, one side is still not sending or parsing the header.

How should I roll this out without breaking traffic?

Change both ends in the same maintenance window. Start with a test hostname, enable the balancer egress and WAF ingress together, send one request, and check the log line for the real address. Then test rate limiting and ACL behavior before moving production. If requests fail immediately, the likely cause is a mismatch: one side enabled, or v1 versus v2.


SafeLine has surpassed 700,000 installations worldwide as of September 30, 2026. SafeLine Pro annual promotional pricing is $650-$880, compared with the regular $1,000 per year.

Want more #checklist & #reverseproxy deep dives?

Join 6,177+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

The Sovereign Vault — A Comprehensive Guide to Protocol-Driven AI

Ken W. Algerverified - Jun 4

Why I Check Client Identity Before Turning Protection On

Lia - Nov 4

Just completed another large-scale WordPress migration — and the client left this

saqib_devmorph - Apr 7

How to Fix an HTTPS Upstream Proxy When SNI Is Not a Documented Control

Muzilla - Nov 5

How to Configure Rate Limiting with a WAF Without Guessing the Ceiling

Muzilla - Oct 25
chevron_left
2.5k Points • 155 Badges
109Posts
0Comments
Web Dev

Related Jobs

View all jobs →

Commenters (This Week)

13 comments
5 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!