Python,Flask客户端IP地址 [英] Python, Flask client ip address
问题描述
我需要记录我使用Python和Flask创建的Web应用程序的每个用户的IP地址.
I need to log the IP address of every user of my webapp, that I've created with Python and Flask.
我正在使用
request.remote_addr
但这将返回应用程序部署到的服务器的IP地址.对此有任何解决办法吗?
But that's return the IP address of the server the app is deployed to. Any fixes to this?
推荐答案
如何部署flask应用程序?
How do you deploy the flask application?
我猜您是通过像nginx这样的反向代理服务器来部署应用程序的,对吧?
I guess you deploy your app via a reverse-proxy server like nginx, right?
如果这样做,则 request.remote_addr
是服务器的地址,因为服务器将客户端的请求发送到应用程序并将响应发送到客户端.
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.
要解决此问题,请参阅: http://flask.pocoo.org/docs/0.11/deploying/wsgi-standalone/#proxy-setups
To fix this, see: http://flask.pocoo.org/docs/0.11/deploying/wsgi-standalone/#proxy-setups
这篇关于Python,Flask客户端IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!