Amazon Elastic Load Balancer and Forwarding Real-IP Nginx

This article is for Amazon AWS only. For forwarding visitor real IP in nginx proxy setup, check this.

If you are running nginx on Amazon EC2 instance, behind Amazon Elastic Load Balancer (ELB), for any IP-specific nginx config and/or applicaiton code to work, you need to do following:

Open /etc/nginx/nginx.conf file

Add following inside http {..} block

real_ip_header X-Forwarded-For;

Then just reload nginx for change to take effect.

Security Consideration:

If your nginx EC2 instance can be accessed directly, apart from traffic coming through Elastic Load Balancer, then its better to change:


to fixed IP address assigned to Elastic Load Balancer.

If IP address for ELB is, then it should look like:


2 responses to “Amazon Elastic Load Balancer and Forwarding Real-IP Nginx”