ruby on rails - Can't get past AWS load balancer to get real IP Address -


i have tried following requests , put them in controller:

request.remote_ip  request.env['http_x_forwarded_for']  request.env['remote_addr']  

these give me correct visitor's ip address: 50.67.168.53 (that points location: vancouver)

however, when in production , check chrome's headers under network,

remote address: 54.213.94.198:80 (oregon)

oregan location of aws load balancer.

my question is, there way remote address point vancouver (instead or oregon) in controller or model , make sure stays way after runs through load balancer? need ip address determine location of visitor insert mailchimp api.

i read following article, kind of understand happening, don't know how implement these changes:

https://serversforhackers.com/so-you-got-yourself-a-loadbalancer

i have rails 3.2 application behind nginx deployed on aws elb , code works me:

def parse_ip   # string of comma separated list of ip addresses   # first 1 outer address   # other may load balancers, routers, etc ...   # example: '195.168.122.106, 172.31.19.59'   ips = request.env['http_x_forwarded_for']   return ips.split(',').first if ips   # fall   request.remote_ip end 

with ngnix config in location block:

location @thin_cluster   {     proxy_set_header x-real-ip         $remote_addr;     proxy_set_header x-forwarded-for   $proxy_add_x_forwarded_for;     ... } 

Popular posts from this blog