HTTP_X_REAL_IP

$_SERVER['REMOTE_ADDR'];得到的都是服务器的地址

$_SERVER['HTTP_X_REAL_IP'];得到的都是客户端的地址

nginx 代理模式下,获取客户端真实IP
在nginx中设置:

proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

后端程序可以从Server变量HTTP_X_REAL_IP和HTTP_X_FORWARDED_FOR中获取用户的ip地址。

HTTP_X_REAL_IP的值是nginx得到的用户REMOTE_ADDR

参考地址:http://doubao.javaeye.com/blog/427619

猜你喜欢

转载自hck.iteye.com/blog/2204238