Welcome! Log In Create A New Profile

Advanced

Re: set_real_ip_from, real_ip_header directive in ngx_http_realip_module

Maxim Dounin
June 29, 2017 11:34AM
Hello!

On Thu, Jun 29, 2017 at 09:08:40AM -0400, foxgab wrote:

> if nginx is behind another proxy, that proxy set the X-Forwarded-for header
> with the real client ip, and the configration of nginx is :
>
> location / {
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> real_ip_header X-Forwarded-For;
> set_real_ip_from 192.168.0.0/16;
> }
>
> whether the real client ip or the address of the proxy will add in the
> X-Forwarded-For header?
> will the value of $remote_addr changes only after real_ip_header directive
> or at the beginning of the context?

The order of the directives in the nginx configuration is not
important (except a few cases where it is explicitly outlined,
like location blocks with regular expressions or rewrite module
instructions). Directives merely set various options for request
processing, and it doesn't matter where you set the option.

The realip module, when configured in a location context, changes
client's address as seen by nginx right after the location
configuration is choosen (and the request is processed by the
rewrite module, if any), before access-related checks.

That is, in the configuration above the realip module will change
the client's address before the "proxy_set_header" directive will
use it. As such, X-Forwarded-For as sent to the backend will
include client address set by the realip module, and the above
configuration will result in duplicate addresses in
X-Forwarded-For.

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

set_real_ip_from,real_ip_header directive in ngx_http_realip_module

Nishikubo Minoru February 27, 2017 08:00PM

Re: set_real_ip_from, real_ip_header directive in ngx_http_realip_module

Maxim Dounin February 28, 2017 08:42AM

Re: set_real_ip_from, real_ip_header directive in ngx_http_realip_module

Nishikubo Minoru February 28, 2017 07:58PM

Re: set_real_ip_from, real_ip_header directive in ngx_http_realip_module

foxgab June 29, 2017 09:08AM

Re: set_real_ip_from, real_ip_header directive in ngx_http_realip_module

Maxim Dounin June 29, 2017 11:34AM

Re: set_real_ip_from, real_ip_header directive in ngx_http_realip_module

foxgab July 03, 2017 04:57AM

Re: set_real_ip_from, real_ip_header directive in ngx_http_realip_module

Maxim Dounin July 03, 2017 09:10AM

Re: set_real_ip_from,real_ip_header directive in ngx_http_realip_module

mohitmehral March 23, 2017 01:45AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 269
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready