`
iwebcode
  • 浏览: 2014213 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

使用Nginx代理模式,后端程序得到用户IP的方法

 
阅读更多

转载:http://blog.csdn.net/hjue/article/details/4351065


在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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics