flask 搭建的网站, nginx 做反向代理,请问怎么获取真实 ip 啊?
如果是通过 flask 的 request.remote_addr 获取的 ip 都是 127.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;
因此通过
from flask import request
ip=request.headers['X-Forwarded-For']
就可以获取真实 ip
因为 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;
因此通过
from flask import request
ip=request.headers['X-Forwarded-For']
就可以获取真实 ip