[英]Rails Heroku SocketError: getaddrinfo: Name or service not known
I am on a heroku app, Ruby 2.2.0, Rails 4.0.12 and using the geokit-rails gem.我在使用 heroku 应用程序、Ruby 2.2.0、Rails 4.0.12 并使用 geokit-rails gem。
When I do a IpGeocoder.geocode(request.remote_ip)
I get the error:当我做一个IpGeocoder.geocode(request.remote_ip)
我得到错误:
Caught an error during Ip geocoding call: getaddrinfo: Name or service not known
I searched online and found that the solution is to make an initialiser and require a library:我在网上搜了一下,发现解决办法是做一个初始化器,需要一个库:
require 'resolv-replace'
When I do so I get the error:当我这样做时,我收到错误:
Caught an error during Ip geocoding call: Hostname not known: api.hostip.info
I am not sure what I should do then.我不知道我应该做什么。 On my development machine works fine.在我的开发机器上工作正常。 Any clue what the issue is?任何线索是什么问题?
Heroku uses forwarding, that causes request.remote_ip
return internal heroku ip address, which cannot be processed by IpGeocoder for some reason. Heroku 使用转发,这导致request.remote_ip
返回内部 heroku ip 地址,由于某种原因无法被 IpGeocoder 处理。
Try to use request.env['HTTP_X_FORWARDED_FOR']
insted.尝试使用request.env['HTTP_X_FORWARDED_FOR']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.