odoo / docker

Other
931 stars 1.51k forks source link

Unable to obtain the real address of the external client #488

Open Etren opened 5 months ago

Etren commented 5 months ago

The configuration file sets proxy_mode=True, and nginx also sets a reverse proxy, but the real address of the external client cannot be obtained in the container.

How to get the real address of an external client?

docker log

2024-01-11 15:24:50,858 16 INFO test odoo.addons.base.models.res_users: Login successful for db:test login:admin@test.com from 172.21.0.1 
2024-01-11 15:24:52,893 16 INFO test odoo.addons.base.models.res_users: Login successful for db:test login:admin@test.com from 172.21.0.1 
2024-01-11 15:25:49,416 19 INFO test odoo.addons.base.models.res_users: Login successful for db:test login:admin@test.com from 172.21.0.1 
2024-01-11 15:45:32,613 16 INFO test odoo.addons.base.models.res_users: Login successful for db:test login:admin@test.com from 172.21.0.1 
2024-01-11 15:49:47,907 19 INFO test odoo.addons.base.models.res_users: Login successful for db:test login:admin@test.com from 172.21.0.1 
2024-01-11 16:18:54,757 16 INFO test odoo.addons.base.models.res_users: Login successful for db:test login:admin@test.com from 172.21.0.1

odoo.conf

[options]
addons_path = /mnt/extra-addons

dbfilter = ^%d$
list_db = False

proxy_mode = True

limit_memory_hard = 1677721600
limit_memory_soft = 629145600
limit_request = 8192
limit_time_cpu = 600
limit_time_real = 1200
max_cron_threads = 1
workers = 6

Nginx Proxy

#PROXY-START/

location ^~ /
{
    proxy_pass http://127.0.0.1:8069/;
    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 REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache

    set $static_fileuRKYjIm2 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
        set $static_fileuRKYjIm2 1;
        expires 1m;
    }
    if ( $static_fileuRKYjIm2 = 0 )
    {
        add_header Cache-Control no-cache;
    }
}
#PROXY-END/
enayfuos commented 4 months ago

Hello,

you need to add :

real_ip_header    X-Forwarded-For;
real_ip_recursive on;

to the top of your nginx conf. and _proxy_setheader X-Forwarded-Host $host; in headers instead of _proxy_setheader Host $host;

If your are behind an HaProxy for example, you need to add _set_real_ip_from HaProxy_serverIP; to the top of your nginx file.

lathama commented 3 months ago

@Etren does the above answer help you here? Can this issue be closed?