← All insights
ENGINEERING JOURNAL / Web Server Engineering

Nginx Real IP: Trust the Proxy Chain Deliberately

Restore accurate Nginx client addresses by mapping trusted proxy hops, selecting the intended header and testing spoofed headers from an untrusted source.

Nginx Real IP: Trust the Proxy Chain DeliberatelyNginx Real IP: Trust the Proxy Chain Deliberately — conceptual 3D-style vector showing Client header, Trusted proxy, Real IP selection, Origin access log, Untrusted source, Rate policy.. Conceptual teaching illustration; connections show the investigation flow rather than a vendor deployment topology.CLOUVENIX / WEB SERVER ENGINEERINGNginx Real IP: Trust the Proxy Chain Deliberately01Client header02Trusted proxy03Real IP selection04Origin access log05Untrusted source06Rate policyConceptual investigation flow / Nginx Real IP: Trust the Proxy Chain Deliberately
Nginx Real IP: Trust the Proxy Chain Deliberately — conceptual 3D-style vector showing Client header, Trusted proxy, Real IP selection, Origin access log, Untrusted source, Rate policy.
TOPICENGINEERING NOTES
01

Context

A reverse proxy sits in front of Nginx, so the origin sees the proxy's network address. Forwarded headers can recover client context, but those headers are input supplied across a trust boundary. The real-IP configuration must identify which immediate senders are authorized to assert replacement addresses.

Prepare a diagram of actual proxy hops, their maintained address ranges and the header contract at each hop. Confirm whether clients can reach the origin directly. Check the Nginx build and installed module support with nginx -V. A logging change can also affect access rules and rate-limit keys, so involve the owners of those behaviors.

02

Establish the address contract

  1. Inspect the effective Nginx configuration with nginx -T through approved administrative access. Review only the relevant server and include blocks, and sanitize output before sharing because full configuration can contain sensitive values. Find set_real_ip_from, real_ip_header and real_ip_recursive, then compare their scope with the intended origin server.
  2. Verify what the trusted upstream actually sends. Some environments use X-Forwarded-For, others use a single address header or the PROXY protocol. These are different interfaces. PROXY protocol also needs listener support; selecting it as a header mechanism without matching transport configuration does not establish a working chain.
  3. Test a harmless request through the approved proxy and compare the connection peer, selected client address and supplied chain. Nginx exposes the original connection address through real-IP variables where supported. Use temporary restricted diagnostics or safe log fields, preserving client privacy. The result should match a known test client, not simply look like a public address.
  4. Rehearse an untrusted-header test in a controlled environment. A request from outside trusted proxy ranges must not be allowed to choose its identity merely by adding the same header. If direct origin access is intentionally blocked, verify that boundary independently and test the configured trust behavior without opening broad temporary access.
03

An illustrative overbroad trust rule

In an illustrative application, the origin trusts replacement headers from every source. A direct request can then supply a chosen address that affects access logs and an IP-based policy. The correction is a maintained trusted-sender list and a tested proxy-header contract. Merely enabling recursive processing does not fix overbroad sender trust.

ObservationCheckInterpretation
Every client appears as proxyModule, header and trusted senderReplacement not applied
Old or unexpected client selectedProxy chain and recursionAddress-selection contract differs
Direct request controls identitySender trust scopeSpoofable assertion boundary
Correct logs, wrong policy behaviorEffective variables used by rulesDownstream configuration mismatch
04

Correct and verify dependent behavior

Preserve the old configuration and modify only the relevant trust and header settings. Run nginx -t before an approved reload. Keep proxy address ranges maintained through the provider's supported source; an obsolete list can cause either missing replacements or unintended trust.

Verify known-client logging, untrusted-header handling and policies that depend on the resulting address. Include IPv6 paths where used. If multiple proxies remain, test the complete chain rather than one manually constructed header alone. Record what the origin considers the connection peer and the client identity.

05

Maintain the trust map

Monitor unexpected proxy addresses and abrupt changes in client-address distribution. Document header ownership, trusted-range updates and direct-origin access policy. Clouvenix server hardening can help review the interaction between origin trust and application controls.

Technical reference

Nginx real-IP module.