I need to store visitors' IP address to our database and here's the way I am trying to do that:
@ip = request.remote_ip
@ip = request.env['REMOTE_ADDR']
But in both cases, the @ip
variable stored the value 127.0.0.1, even when I deploy the app to Amazon EC2 instance.
When I check http://www.whatismyip.com/, it shows my IP as 109.175.XXX.X.
Thus, why does the ruby variable always display the 127.0.0.1 address? How do I get the real IP?
EDIT: Here's the output of following:
request.env['HTTP_X_FORWARDED_FOR'] =>
request.remote_ip => 127.0.0.1
request.env['REMOTE_ADDR'] => 127.0.0.1
request.ip => 127.0.0.1
I thought that the problem is just on my side, but I sent links to 3 of my friends and all of them see the same IP, just 127.0.0.1.
I am solving this issue the whole day and still no success.
Thank you