Didip Kerabat
unread,Apr 25, 2013, 12:08:56 PM4/25/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to python-...@googlegroups.com
I set xheaders=True inside HTTPServer:
server = tornado.httpserver.HTTPServer(self.application, xheaders=True)
And I set both X-Real-IP and X-Forwarded-For on Nginx (This is a fairly common setup, nothing fancy).
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
On my Nginx, $remote_addr is unfortunately the proxy's IP.
$remote_addr value is what I get from Tornado's request.remote_ip
$proxy_add_x_forwarded_for value is what I want.
Looking inside Tornado's httpserver.py, looks like it always try to get the X-Real-IP first.
if connection and connection.xheaders:
# Squid uses X-Forwarded-For, others use X-Real-Ip
ip = self.headers.get(
"X-Real-Ip", self.headers.get("X-Forwarded-For", self.remote_ip))
if netutil.is_valid_ip(ip):
self.remote_ip = ip
So my question is:
Should Tornado try to get X-Forwarded-For first? If not then I supposed I could remove the X-Real-IP setting from Nginx.
- Didip -