xheaders, logging and nginx

45 views
Skip to first unread message

cow...@gmail.com

unread,
Feb 17, 2021, 5:22:11 PM2/17/21
to Tornado Web Server
I have a tornado server behind nginx reverse proxy. In the nginx.conf http section I have global proxy settings:

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    server {
        ...

        location /app {
           # tornado listening on 1234
            proxy_pass http://localhost:1234/app;
        }
    }

Tornado configuration:

    app = tornado.web.Application(...)
    server = tornado.httpserver.HTTPServer(app, xheaders=True)

But Tornado logger still sees all requests come from 127.0.0.1

How should I setup nginx to pass the actual IP to tornado?

Adrian

unread,
Feb 19, 2021, 4:24:21 PM2/19/21
to Tornado Web Server
That's exactly what I do and it works. Try with just X-Real-IP?

Peter Lai

unread,
Feb 19, 2021, 5:32:37 PM2/19/21
to python-...@googlegroups.com
Does this require the http_realip_module to be built into nginx ?

--
You received this message because you are subscribed to a topic in the Google Groups "Tornado Web Server" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-tornado/1TFVz0_pW74/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-tornad...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-tornado/3d195d70-c181-459f-81aa-521a78d026f3n%40googlegroups.com.

Ben Darnell

unread,
Feb 28, 2021, 9:38:34 PM2/28/21
to Tornado Mailing List
On Wed, Feb 17, 2021 at 5:22 PM cow...@gmail.com <cow...@gmail.com> wrote:
I have a tornado server behind nginx reverse proxy. In the nginx.conf http section I have global proxy settings:

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


You only need one of these. Having both X-Real-IP and X-Forwarded-For should be harmless but won't help; I think it might be breaking things to have two different settings for X-Forwarded-For. I believe the recommended form is `proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for`. If you're still having trouble, try printing out exactly what you're getting in `self.request.headers.get("X-Forwarded-For")`

-Ben
 
    server {
        ...

        location /app {
           # tornado listening on 1234
            proxy_pass http://localhost:1234/app;
        }
    }

Tornado configuration:

    app = tornado.web.Application(...)
    server = tornado.httpserver.HTTPServer(app, xheaders=True)

But Tornado logger still sees all requests come from 127.0.0.1

How should I setup nginx to pass the actual IP to tornado?

--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-tornado/c2492303-2097-4dc2-922b-b115529f301cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages