Tornado获取客户端IP(补充)

今天发现犯了一个错误,前几天写过一篇“tornado获取客户端IP”,但今天查看数据库中数据时候发现所有的IP均是127.0.0.1(因数据库使用bigint存储,所以数据库中看到IP均是2130706433),在Group中搜索了一下发现Ben以前解释过这个问题


Ben Darnell
Tornado supports both x-real-ip and x-forwarded-for, but you have to set
xheaders=True in your HTTPServer constructor to have it look at either of
them.

-Ben


即tornado支持通过 x-real-ip 或 x-forwarded-for来获取IP,但前提是需要在你的HTTPServer实例中增加xheaders=True参数,如:http_server = tornado.httpserver.HTTPServer(Application(), xheaders=True),否则通过self.request.remote_ip取到的IP只能是127.0.0.1。

BTW:nginx配置x-forwarded-for时只需在反向代理规则中增加一行:proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

以上内容均来自:http://groups.google.com/group/python-tornado/browse_thread/thread/c2898018e40125c9

Via:Chairo@2011年10月26日-EOF-

添加新评论 »

captcha 请输入验证码