使用 Nginx 时如何在 Odoo 上获取用户 IP 地址

How to get User IP Address on Odoo when I am using Nginx

我在 Odoo 中使用 Nginx,我试图获取用户 ip 地址:

没有 Nginx 这个代码块

request.httprequest.environ['REMOTE_ADDR']

returns 用户的 ip_address

但是对于 Nginx,它 returns

127.0.0.1

而且很正常,如果有人能帮忙,我想在Odoo上获取真实的IP地址

这是我的 Nginx 配置文件:

location / {
    proxy_pass http://127.0.0.1:7777;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header REMOTE_ADDR $remote_addr;
}

尝试查询 X-real-IP

将您的代码更改为:

request.httprequest.environ['HTTP_X_REAL_IP']