Odoo Nginx

Odoo Logs with 127.0.0.1 in Reverse Proxy with Nginx (Solution)

How to get the actual IP address of the user in your Odoo log file

After setting up your Odoo server perfectly and successfully putting it behind an Nginx with reverse proxy by adding all the supposedly necessary directives to pass all the headers to your proxy server.

proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;

You test your link tracking feature and realised that you can’t track WHO has clicked on the links and the total clicks stuck at a grand total of 1….

Feeling utter frustration you check the Odoo logs and find the following:

Checking Nginx logs everything looks perfect! (Note: last 2 octets of ip address masked)

After much digging and hair pulling finally the solution was found…

Here is the solution!

Go to the following file and edit it

/opt/odoo/odoo-10.0/odoo/service/wsgi_server.py

Add the following line:

def application(environ, start_response):
    if config['proxy_mode'] and 'HTTP_X_FORWARDED_HOST' in environ:
        werkzeug.serving.WSGIRequestHandler.address_string = lambda self: self.headers.get('x-real-ip', self.client_address[0])
        return werkzeug.contrib.fixers.ProxyFix(application_unproxied)(environ, start_response)
    else:
        return application_unproxied(environ, start_response)

Restart your Odoo and PRESTO! (Note: last 2 octets of ip address masked)

Link tracking works now.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *