我的服务器没有公共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;
}在我的Rails应用程序的控制器中,request.ip和request.remote_ip都会返回服务器的网关地址。
如何获取客户端真实IP?
如何从Rails请求中获取X-Forwarded For值?
发布于 2011-05-26 22:06:55
您应该获得标题值X-forwarded-for
http://en.wikipedia.org/wiki/X-Forwarded-For
发布于 2011-07-24 00:52:00
Rails应该会自动为我们做这件事,但现在的3.x版似乎已经破坏了它
我使用的是:
def ip() request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip endhttps://stackoverflow.com/questions/6139861
复制相似问题