ruby-on-rails – 使用Rails和Nginx获取客户端的真实IP地址?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 使用Rails和Nginx获取客户端的真实IP地址?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我的服务器没有公共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值?

最佳答案
您应该获得标头值X-forwarded-for

http://en.wikipedia.org/wiki/X-Forwarded-For

原文链接:https://www.f2er.com/nginx/435073.html

猜你在找的Nginx相关文章