X-Forwarded-For - How to get

121 views
Skip to first unread message

Monty808

unread,
Jul 6, 2009, 2:29:37 AM7/6/09
to web.py
Hi,

Normally I use env['REMOTE_ADDR'] to get the IP address. But..on
webfaction using wsgi...I have to use X-Forwarded-For to get the IP
address.

So...what is the code to get the IP address?

Thanks

Anand Chitipothu

unread,
Jul 6, 2009, 3:06:48 AM7/6/09
to we...@googlegroups.com


2009/7/6 Monty808 <davidmo...@gmail.com>
Try using web.ctx.ip. If that doesn't work, try web.ctx.env['HTTP_X_FORWARDED_FOR'].


paul jobs

unread,
Jul 6, 2009, 3:36:22 AM7/6/09
to we...@googlegroups.com
web.ctx.env['HTTP_X_FORWARDED_FOR'] wat is this?
--
BidEgg - Worlds best low price Auction site
http://bidegg.com

David Montgomery

unread,
Jul 6, 2009, 5:04:22 AM7/6/09
to we...@googlegroups.com
Here is the repsonse from webfaction that will explain the issue....

> I have two sites running.  One is a static/cgi/php site and the other is a
> wsgi site both using a shared IP.
>
> I use ip = env['REMOTE_ADDR'] to get the remote address.
>
> When I save ip in a table for the static site I see what I believe is the
> correct IP.  On the wsgi site I see 127.0.0.1.  If I remove the wsgi site
> and use a static site then I get the correct referer IP.  Why does this
> happen for a wsgi site?


All requests to your sites are proxied from the front-end web server to
another server internally. So, when the request reaches your app, it's
actually coming from the internal IP 127.0.0.1.

When the request is proxied, the original IP is stored in the X-Forwarded-For
header.

Static/CGI/PHP sites are proxied to our shared Apache+PHP environment. That
environment uses an Apache module to masquerade X-Forwarded-For as
REMOTE_ADDR.

Your other apps do not use that module, so if you need to check IP for those
apps (like a mod_wsgi site) then you need to look at X-Forwarded-For.

Hope that helps!
--
David Montgomery
Chief Technical Officer
Ad Aloha
http://www.AdAloha.com
Honolulu, Hawaii 96815
808-351-5046
Calandar
http://users.adaloha.com/davidmontgomery_calandar


paul jobs

unread,
Jul 7, 2009, 2:05:09 AM7/7/09
to we...@googlegroups.com
thanks david it is the original requesters address
Reply all
Reply to author
Forward
0 new messages