docker icon indicating copy to clipboard operation
docker copied to clipboard

Unable to obtain the real address of the external client

Open Etren opened this issue 7 months ago • 2 comments

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:[email protected] 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:[email protected] 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:[email protected] 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:[email protected] 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:[email protected] 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:[email protected] 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/

Etren avatar Jan 11 '24 16:01 Etren

Hello,

you need to add :

real_ip_header    X-Forwarded-For;
real_ip_recursive on;

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

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

enayfuos avatar Feb 27 '24 16:02 enayfuos

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

lathama avatar Apr 02 '24 17:04 lathama

Thanks for everyone‘s help, the problem has been solved. It may be because the nginx configuration file was not reloaded after updating the configuration file. After restarting the nginx service, the client's real address can be obtained.

Etren avatar Jul 18 '24 01:07 Etren