Getting real client IP from behind NodeBalancer using nginx
I have the HttpRealIpModule installed and configured with:
set_real_ip_from 192.168.255.7; <-- internal IP address of NodeBalancer
real_ip_header X-Forwarded-For;
But all requests are still being logged as coming from
192.168.255.7
in both Rails and nginx logs.
According to the NodeBalancer docs at
this is all I need to do. Am I missing something else?
Thanks.
5 Replies
@obs:
Are you using https (i.e. tcp balancing) if so you can't get the real IP.
Yes, I am using HTTPS and hence am using TCP balancing.
I thought that since nginx is doing the SSL termination I would have full visibility into the request & packet (?)
There are other ways you can get the customer's IP if required. If your app uses some sort of session mechanism, start the session on an unencrypted page, store the real IP, then redirect the user to an encrypted page. Or you could use an unencrypted landing page and redirect the user with the real IP as a GET or POST parameter or something.
x-forwarded-for
transfer at some point during client -> balancer -> nginx -> rails connection.
Reference states that it should work as balancer will terminate the SSL connection:
~~![](<URL url=)
But it doesn't work for me though.
UPD
I was wrong. I'm using TCP instead of HTTPS protocol here.~~