flask.request.remote_addr一直都是127.0.0.1
解决:https://www.jianshu.com/p/98bc849ef01a
proxy_set_header Host $host:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
以上的nginx配置我已经配置了的,将获取对端地址的代码修改为flask.request.headers['X-Real-Ip']即可。
所以代码如下所示:
try:
url_param['ip'] = flask.request.headers['X-Real-Ip']
except KeyError:
url_param['ip'] = flask.request.remote_addr
没有评论:
发表评论