nginx代理的方式运行web.py时IP的获取 #190

Open
singpenguin opened this Issue Nov 17, 2012 · 1 comment

Comments

Projects
None yet
1 participant
@singpenguin

如果使用nginx代理运行web.py,那么使用web.ctx.ip就会得到错误的IP,web.ctx.ip=127.0.0.1,怎样才能获取正确的IP呢,其实nginx在代理时已经把ip地址写进header里面了,但是名字却不是X-Real-IP,而是HTTP_X_REAL_IP,自动的加了http开头,所以呢,我们就可以这样来获取真实的IP地址,web.ctx.env.get('HTTP_X_REAL_IP,web.ctx.ip),这样就是真实的IP。

@ghost

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Nov 17, 2012

google translate says

If you use a the nginx proxy running web.py to use web.ctx.ip get the wrong IP = 127.0.0.1 web.ctx.ip, how to get the correct IP, in fact, nginx in the proxy ip address it written into the header, but the name is not X-Real-IP, but HTTP_X_REAL_IP, automatically add http at the beginning, so, we can be to get the real IP address web.ctx.env.get (' HTTP_X_REAL_IP, web.ctx.ip), so that is the real IP.

ghost commented Nov 17, 2012

google translate says

If you use a the nginx proxy running web.py to use web.ctx.ip get the wrong IP = 127.0.0.1 web.ctx.ip, how to get the correct IP, in fact, nginx in the proxy ip address it written into the header, but the name is not X-Real-IP, but HTTP_X_REAL_IP, automatically add http at the beginning, so, we can be to get the real IP address web.ctx.env.get (' HTTP_X_REAL_IP, web.ctx.ip), so that is the real IP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment