Getting real IP while using nginx working behind Amazon Elastic Load Balancer

30 / Jun / 2014 by Prashant Sharma 0 comments

When placing nginx  web servers behind a Elastic load balancer  , the client IP address from the browser is replaced with the IP address of the load-balancer. This makes difficult to analysis the location of IP

Here’s how you can fix it and capture the real IP.

Prerequisite

Make sure you have http_realip_module with nginx . You can check it this way:

nginx -V

 

Open /etc/nginx/nginx.conf file and add following parameters inside http block.

vi /etc/nginx/nginx.conf

http { ..
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
..}

 

After this reload the nginx and check the access logs.

Note : If the traffic  only coming through elastic load balancer , then set  IP address assigned to elastic load balancer.

Suppose IP address for elastic load balance  is 1.1.1.1, then it should look like

set_real_ip_from 1.1.1.1;
 
Thanks
Prashant Sharma
FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *