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:


Discuss your project
with our experts

No obligation. Limited slots.

Contact Form Business Enquiry

"*" indicates required fields

Please attach any RFP, project specification, or document that you would like to share.
Drop files here or
Max. file size: 5 GB.
    This field is for validation purposes and should be left unchanged.