Real IP on nginx behind AWS ELB with IP filtering

In our installation, we have an AWB ELB that sends general traffic to two EC2 instances running nginx.

These nginx proxies are for many applications, some of these applications have IP restrictions, for example:

  location /admin {
    allow 1.1.1.1;
    allow 1.1.1.2;
    deny all;
    proxy somewhere;
  }

The problem is that I cannot get a real IP client - it appears in nginx logs as private address 172.31.0.0/16

I tried adding:

    set_real_ip_from  0.0.0.0/0;
    real_ip_header    X-Forwarded-For;
    real_ip_recursive on;

But still not get a real IP.

My version of nginx:

    nginx version: nginx/1.4.6
    built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
    TLS SNI support enabled
    configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --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 --add-module=/tmp/nginx-sticky-module-1.1 --with-http_addition_module --with-http_gzip_static_module --with-http_spdy_module --with-http_sub_module --with-mail --with-mail_ssl_module
+4
source share

All Articles