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

已有85条评论 »

  1. Fantastic website. A lot of useful information here. I'm sending it to a few pals ans also sharing in delicious. And naturally, thank you in your sweat!

  2. Fantastic website. A lot of useful information here. I'm sending it to a few pals ans also sharing in delicious. And naturally, thank you in your sweat!

  3. Generic Viagra campioni cialis online for sale canada rx.

  4. Is it safe to take Tadalafil(=potenzmittel cialis lilly, for impotence) while taking Metformin for Diabetes?

  5. en

    These medications for patients who lose their late cialis en verkauf Cialis teens and workup be elucidated.

  6. Hello, always i used to check blog posts here in the early hours in the daylight,

  7. Hello, always i used to check blog posts here in the early hours in the daylight,

  8. On Tuesday, the company's new commercial for viagra images will air on television.

  9. viagra generic available us pills are not for everyone .

  10. and

    Sex enhancer for men: Herbal viagra and adderall A natural sex enhancer for men.

  11. Hello! buy viagra , cialis online , cialis online , buy viagra , cialis online ,

  12. Hello! generic cialis online , viagra generic , generic cialis online , generic cialis online , viagra generic ,

  13. Hello! viagra , buy cialis , canadian viagra , cialis , viagra ,

  14. Hello! buy cialis online , buy viagra online , buy viagra online , buy cialis online , buy viagra online ,

  15. Hello! buy cialis , viagra soft flavoured , sildenafil generic india , viagra , viagra ,

  16. Hello! loans for bad credit , cialis generic , generic cialis ,

  17. Hello! loans for bad credit , loans for bad credit , buy cialis , viagra soft tabs , payday express ,

  18. Hello! payday loans , payday loans , payday loans online , payday loans , cialis ,

  19. Hello! payday loans , cialis , payday loans , payday loans , online payday loans ,

  20. Hello! payday loans online , buy cialis , buy viagra , buy viagra , buy cialis ,

添加新评论 »