Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get client ip from request object? #101

Closed
ashokrkm opened this issue Oct 17, 2010 · 6 comments
Closed

how to get client ip from request object? #101

ashokrkm opened this issue Oct 17, 2010 · 6 comments
Labels

Comments

@ashokrkm
Copy link

is it possible to get the client ip address from request object?

def post_request(worker, req):

@benoitc
Copy link
Owner

benoitc commented Oct 17, 2010

You can check the REMOTE_ADDR header in req.headers .

@ashokrkm
Copy link
Author

can you give this as req.remote_addr ?

@ashokrkm
Copy link
Author

there is no REMOTE_ADDR in req.headers. got only these headers.

HOST
USER-AGENT
ACCEPT
ACCEPT-LANGUAGE
ACCEPT-ENCODING
ACCEPT-CHARSET
KEEP-ALIVE
CONNECTION
REFERER
COOKIE

@davisp
Copy link
Collaborator

davisp commented Oct 25, 2010

@KCastiglione

Do you have a line like this in your nginx config?

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Gunicorn is HTTP, which means the only information it has access too are the current socket connection and the headers that it receives. In a proxy configuration there's no method for getting the remote IP unless you have the proxy server forward that information in a header. Once in a header it should be in req.headers. If that does not appear to be the case, please open another ticket.

@ashokrkm
Copy link
Author

yes adding the line in nginx helped!
thanks a lot

@zffocussss
Copy link
Contributor

hi you can get the remote address with req.peer_addr[0],which is connecting with gunicorn directly.
see below
https://github.com/benoitc/gunicorn/blob/master/gunicorn/http/message.py#L29-L39

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants