Python, Flask client ip address
12,974
How do you deploy the flask application?
I guess you deploy your app via a reverse-proxy server like nginx, right?
If you did that then request.remote_addr
is the address of your server because your server sent client's request to your application and sent the response to the client.
To fix this, see: http://flask.pocoo.org/docs/0.11/deploying/wsgi-standalone/#proxy-setups
Related videos on Youtube
Author by
Brian
Updated on June 04, 2022Comments
-
Brian almost 2 years
I need to log the IP address of every user of my webapp, that I've created with Python and Flask.
I'm using
request.remote_addr
But that's return the IP address of the server the app is deployed to. Any fixes to this?
-
javad over 7 yearsPossible duplicate of Get IP address of visitors using Python + Flask
-
-
Brian over 7 yearsI deploy the app with supervisor on AWS
-
Brian over 7 yearsActually, I found out that this
request.headers.get('X-Forwarded-For', request.remote_addr)
works well for my needs -
Arel almost 4 years
request.environ['REMOTE_ADDR']
andrequest.remote_addr
are the same thing (and not solving the problem the OP asked about.)