【发布时间】:2020-08-21 03:26:26
【问题描述】:
我正在尝试获取访问该站点的用户的真实 IP 地址。 为此,我想为 API 服务添加自定义授权。在这两种情况下使用标头似乎是个好主意。
问题是我无法在由 nginx 和 gunicorn 网络服务器提供的烧瓶应用程序中获取自定义标头。获取“remote_addr”标头仅返回 127.0.0.1 IP 地址,尽管我是从外部网络发布的,而不是从本地主机发布的。
这是我的配置文件:
部分 nginx 配置 //1.14.2
location / {
# forward application requests to the gunicorn server
proxy_read_timeout 30s;
proxy_send_timeout 30s;
proxy_connect_timeout 30s;
proxy_pass http://127.0.0.1:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
add_header CLIENT-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
gunicorn 配置的一部分 //20.0.4
[program:wapp]
command=/home/deeslo/processor/venv/bin/gunicorn -b localhost:5000 -w 4 microservice:app
directory=/home/deeslo/processor
user=deeslo
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
当我检查标头时,我看不到来自 Nginx 的 X-Real-IP/CLIENT-IP 以及我在烧瓶中发送的其他自定义标头生成响应标头。
我错过了什么? 还没解决。
【问题讨论】: