eth*_*han 8 networking web-services ruby-on-rails nginx ip-address
我的服务器没有公共IP地址,所以我不知道如何获取真实客户端的IP地址.
这是我的nginx的配置:
location / {
proxy_pass http://domain1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Run Code Online (Sandbox Code Playgroud)
在我的Rails应用程序的控制器中,request.ip并request.remote_ip返回我的服务器的网关地址.
我怎样才能获得客户的真实IP?
如何从Rails请求中获取X-Forwarded-For值?
Kev*_*vin 21
Rails应该是为我们自动完成的,但它似乎被当前的3.x打破了
我正在使用这个:
def ip() request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip end
Run Code Online (Sandbox Code Playgroud)
您应该获得标头值X-forwarded-for
http://en.wikipedia.org/wiki/X-Forwarded-For
| 归档时间: |
|
| 查看次数: |
13840 次 |
| 最近记录: |