Nginx反代后,IP都成了本地IP127.0.0.1
,但是Nginx的配置中设置了以下属性:
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
里面就有真实IP,可以通过以下代码获取:
from flask import request
ip=request.headers['X-Forwarded-For']