﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
1201	Realip module fails if X-Forwarded-For includes port number	Jontsa@…		"We encountered this issue while trying to get realip module to work in Nginx backends behind Azure load balancer. Azure adds port-number to X-Forwarded-For header which seems to break realip functionality.

Example of X-Forwarded-For from our logs at Azure:
{{{
""70.32.40.2:35104""
}}}

I setup a local nginx server with PHP script that dumps remote address and x-forwarded-for headers from PHP $_SERVER variable.

Virtual host config:
{{{
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

    real_ip_header X-Forwarded-For;
    real_ip_recursive on;
    set_real_ip_from 192.168.0.2;
    set_real_ip_from 127.0.0.1;

    fastcgi_param NGINX_REALIP_REMOTE_ADDR $realip_remote_addr;
}
}}}

I sent tests using curl. When I added port number to x-forwarded-for header, the REMOTE_ADDR value was incorrect.

{{{
$ curl http://localhost/testi/realip.php
PHP _SERVER variables:
  NGINX_REALIP_REMOTE_ADDR: 127.0.0.1
  HTTP_X_FORWARDED_FOR:     
  REMOTE_ADDR:              127.0.0.1

$ curl --header ""X-Forwarded-For: 12.34.56.78"" http://localhost/testi/realip.php
PHP _SERVER variables:
  NGINX_REALIP_REMOTE_ADDR: 127.0.0.1
  HTTP_X_FORWARDED_FOR:     12.34.56.78
  REMOTE_ADDR:              12.34.56.78

$ curl --header ""X-Forwarded-For: 12.34.56.78:60033"" http://localhost/testi/realip.php
PHP _SERVER variables:
  NGINX_REALIP_REMOTE_ADDR: 127.0.0.1
  HTTP_X_FORWARDED_FOR:     12.34.56.78:60033
  REMOTE_ADDR:              127.0.0.1
}}}

Tested with Nginx 1.10.0 on Ubuntu Xenial and with Nginx 1.10.3 on Centos."	defect	closed	minor		nginx-module	1.10.x	wontfix	realip proxy azure		Linux devi-php7 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux	"nginx version: nginx/1.10.0 (Ubuntu)
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads"
