<div dir="ltr">On Fri, Feb 10, 2017 at 7:33 AM, Maxim Dounin wrote:<br>> And real_ip_recursive switched on means that this happens<br>> recursively.  As a result, with the configuration in question<br>> nginx will use the first address in X-Forwarded-For provided, if<br>> any (assuming all addresses are valid).<br>> Note that "set_real_ip_from <a href="http://0.0.0.0/0">0.0.0.0/0</a>" makes client's address as<br>> seen by nginx easily spoofable by any client, and it is generally<br>> a bad idea to use it in production.<br><br>Thank you for the reply, Maxim. "set_real_ip_from <a href="http://0.0.0.0/0">0.0.0.0/0</a>" does indeed seem like a bad idea in production. Thank you for calling that out.<br><br>I am confused by this statement in the documentation:<br><a href="http://nginx.org/en/docs/http/ngx_http_realip_module.html">http://nginx.org/en/docs/http/ngx_http_realip_module.html</a><br>"If recursive search is enabled, the original client address that matches one of the trusted addresses is replaced by the last non-trusted address sent in the request header field."<br><br>The language "last non-trusted address" suggests that NGINX looks for something in real_ip_header which does not match set_real_ip_from. But maybe I am interpreting that incorrectly.<br><br>If set_real_ip_from were set correctly to the host's content delivery network, load balancer, and reverse proxy infrastructures, then my interpretation would make sense, as $remote_addr would then get set to the client's public IP, even if the client has network address translation and forward proxy infrastructures which append to X-Forwarded-For. But in your answer, wouldn't $remote_addr be set to the client's private IP address if their firewall/gateway adds that private IP address to X-Forwarded-For while it does the NATing? That doesn't seem very useful.<br><br>This is an example situation I'm thinking of (all the IPs are random, and are the IPs "facing" NGINX):<br><br>set_real_ip_from <a href="http://10.6.1.0/24">10.6.1.0/24</a>, <a href="http://8.47.98.0/24">8.47.98.0/24</a>;<br>real_ip_header X-Forwarded-For;<br>real_ip_recursive on;<br><br>client's computer (192.168.1.79) > client's gateway (178.150.189.138) > my content delivery network (8.47.98.129) > my load balancer (10.6.1.56) > my NGINX box<br><br>X-Forwarded-For = 192.168.1.79, 178.150.189.138, 8.47.98.129<br><br>I think in your answer, $remote_addr would be set to 192.168.1.25, while in my interpretation, it would be set to 178.150.189.138. And in either case, $realip_remote_addr is 10.6.1.56.<br><br>It would be a strangely configured client gateway / firewall / NAT / proxy that adds to X-Forwarded-For, but it can happen.<br><br>I guess I am still confused.<br><br> ~ Paul Nickerson</div>

<br>
<div><div><span style="border-collapse:collapse"><p style="margin-top:0px;margin-right:0in;margin-bottom:5pt;margin-left:0in"><span style="font-size:7.5pt"><font color="#666666" face="tahoma, sans-serif"><b>CONFIDENTIALITY NOTICE</b></font></span></p></span></div></div><div><span style="border-collapse:collapse"><p><span style="color:rgb(102,102,102);font-family:tahoma,sans-serif;font-size:10px">The attached information is PRIVILEGED AND CONFIDENTIAL and is intended only for the use of the addressee named above.  If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, please be aware that any dissemination, distribution or duplication of this communication is strictly prohibited. If you receive this communication in error, please notify us immediately by telephone, delete the message and destroy any printed copy of the message. Thank you.</span></p></span></div>