Nginx Real IP When Using a Load Balancer

If you’re using a load balancing service like the AWS Elastic Load Balancer, your log files are probably populated with every request coming from the same IP - your load balancer. Here’s a quick fix to get the real IP from your users.

Open up /etc/nginx/nginx.conf and add the following text just after your http block opens:

real_ip_header X-Forwarded-For;

If your server can be accessed outside of the load balancer, change that to the IP address of your load balancer:


After this is done just reload nginx:

sudo nginx -s reload
© 2014 - 2021 · Home ·