Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Etren opened this issue Jan 11, 2024 · 3 comments
Closed

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

Etren opened this issue Jan 11, 2024 · 3 comments

Comments

@Etren
Copy link

Etren commented Jan 11, 2024

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
Copy link

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.

@lathama
Copy link

lathama commented Apr 2, 2024

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

@Etren
Copy link
Author

Etren commented Jul 18, 2024

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 Etren closed this as completed Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants