What this thread does
Do first: define set_real_ip_from using only the actual load balancer's trusted source ranges before enabling real_ip_header X-Forwarded-For.
Short answer
As of November 2026, nginx stable 1.30.8 has the real-IP behavior described below. Client identity and hop history are separate: $remote_addr becomes the selected client, while $realip_remote_addr keeps the original client address. (proxy variable)
Choose / don't choose
- Trusted LB chain: choose recursion when each trusted intermediary sanitizes or correctly appends forwarding data; don't trust arbitrary Internet sources.
- Client identity: choose
$remote_addrafter real-IP handling for the selected client. - Connection history: choose
$realip_remote_addrwhen recording the original connecting peer; don't relabel it as the end user's address.
Not for: Fastify application rate-limit trust; see fastify-login-rate-limit-trusted-proxy.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
set_real_ip_from | Actual LB addresses/CIDRs only; no trusted sources by default; never use a catch-all Internet trust range | nginx 1.30.8 | trust directive |
real_ip_header | X-Forwarded-For for that LB contract; default X-Real-IP | nginx 1.30.8 | header directive |
real_ip_recursive | on selects the last non-trusted address; default off selects the last header address when peer is trusted | nginx 1.30.8 | recursive selection |
proxy_set_header X-Real-IP | $remote_addr as in the proxy-header example | nginx HTTP proxying | proxy header example, real-IP |
proxy_set_header X-Forwarded-For | For a nonempty, sanitized incoming chain: "$http_x_forwarded_for, $realip_remote_addr"; if absent, emit only the original peer | Original-peer history; realip variable available since 1.9.7 | variable, reported header recipe |
The header recipe assumes only your trusted LB can reach this listener and that it emits a nonempty canonical chain. Preserve a separate selected-client header for upstream identity decisions. A preserved incoming chain can still contain untrusted earlier entries; applications must apply their own trust policy.
Order of operations
1. Inventory every connecting proxy and the source address nginx actually sees. Permit the real-IP module only on those peers and establish how the LB handles client-supplied forwarding headers. Read build parameters with nginx -V if module availability is uncertain; the module requires --with-http_realip_module (module). 2. The $remote_addr variable changes when http_realip_module is used. Combining the documented variable definitions explains why the standard append helper sees the rewritten client, not the original LB. (proxy definition) (source) 3. For client a.a.a.a through peer b.b.b.b, distinguish selected client from original peer in logs. The report expects a.a.a.a, b.b.b.b and observes a.a.a.a, a.a.a.a. Do not append both values without a defined upstream contract (reported example). 4. Use the nginx -t option to test configuration-file syntax, then -s reload to reload configuration, then compare requests through the LB with direct requests carrying a forged forwarding header. Require a direct untrusted peer to retain its observed address (CLI, trust semantics).
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
a.a.a.a, a.a.a.a | $remote_addr changes when http_realip_module is used; the report received a.a.a.a, a.a.a.a | Append the original peer for hop history, with an absent-header branch; use the selected-client value separately | reported chain, proxy variable |
Proxy or forged address in $remote_addr | Check trusted hops, header selection, recursion and trust scope | Compare observed peer/header chain with real LB ranges; restrict trust and correct the LB sanitization contract | real-IP selection |
Missing
- No deployment CIDRs or sanitization contract are given. Do not copy sample private ranges as a universal trust list.
- This configuration does not authenticate a forwarded chain received from arbitrary clients.
Checked
2026-11-24; nginx stable 1.30.8 download and November 23, 2026 changelog, real-IP/proxy/CLI references, pierrefevrier's dated report and its original-peer answer read. No proxy commands or requests executed.
Started from a post by @nginx, packaged by the editor. Original post