Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1513 Vistas

How can I make Odoo Discuss (Live Chat) update messages without needing a page refresh?

Is my Nginx configuration correct for longpolling and WebSockets?

Do I need to adjust any Odoo settings for WebSockets to work properly?


Any guidance would be greatly appreciated!


(NGINX Sample File)


# Upstream Odoo servers

upstream odoo17 {

    server 127.0.0.1:1700;

}


upstream odoo17chat {

    server 127.0.0.1:8072;

}


# ---------------------- SHOP.COM ----------------------

server {

    listen 443 ssl;

    server_name shop.com www.shop.com;


    proxy_read_timeout 720s;

    proxy_connect_timeout 720s;

    proxy_send_timeout 720s;


    # Add Headers for Odoo Proxy Mode

    proxy_set_header X-Forwarded-Host $host;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header X-Forwarded-Proto $scheme;

    proxy_set_header X-Real-IP $remote_addr;


    # Log Files

    access_log /var/log/nginx/shop.access.log;

    error_log /var/log/nginx/shop.error.log;


    # Redirect requests to Odoo Backend Server

    location / {

        proxy_redirect off;

        proxy_pass http://odoo17;

    }


    location /longpolling {

        proxy_pass http://odoo17chat;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection "upgrade";

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $host;

        proxy_http_version 1.1;

    }


    # SSL Configuration

    ssl_certificate /etc/letsencrypt/live/shop.com/fullchain.pem;

    ssl_certificate_key /etc/letsencrypt/live/shop.com/privkey.pem;

    include /etc/letsencrypt/options-ssl-nginx.conf;

    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

}


# Redirect HTTP to HTTPS

server {

    listen 80;

    server_name shop.com www.shop.com;

    return 301 https://$host$request_uri;

}


# ---------------------- WEB.SHOP.COM ----------------------

server {

    listen 443 ssl;

    server_name web.shop.com www.web.shop.com;


    proxy_read_timeout 720s;

    proxy_connect_timeout 720s;

    proxy_send_timeout 720s;


    # Add Headers for Odoo Proxy Mode

    proxy_set_header X-Forwarded-Host $host;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header X-Forwarded-Proto $scheme;

    proxy_set_header X-Real-IP $remote_addr;


    # Log Files

    access_log /var/log/nginx/web_shop.access.log;

    error_log /var/log/nginx/web_shop.error.log;


    # Redirect requests to Odoo Backend Server

    location / {

        proxy_redirect off;

        proxy_pass http://odoo17;

    }


    location /longpolling {

        proxy_pass http://odoo17chat;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection "upgrade";

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $host;

        proxy_http_version 1.1;

    }


    ssl_certificate /etc/letsencrypt/live/web.shop.com/fullchain.pem;

    ssl_certificate_key /etc/letsencrypt/live/web.shop.com/privkey.pem;

}


(Sample Conf File for Odoo17)


[options]

admin_passwd = ****

http_port = 1700

logfile = /var/log/odoo/odoo17.log

addons_path = /opt/odoo17/odoo17/addons,/opt/odoo17/odoo17/custom

proxy_mode = True

workers = 2

db_name = False

db_user = odoo17

db_port = 5432

db_host = localhost

db_password = ****

xmlrpc_interface = 127.0.0.1

longpolling_port = 8072

dbfilter = ^%h$

Avatar
Descartar

Hi, can you confirm if you use any load balancers?

Mejor respuesta

Assessment of Nginx Configuration:

This Nginx configuration is largely correct and robust for Odoo's longpolling and WebSockets. Here are the key points:

  • Separate Upstreams (odoo17, odoo17chat): This is a clean way to define the main Odoo application and its longpolling backend.
  • Correct Ports: 1700 for main Odoo and 8072 for chat are correctly passed to the upstreams.
  • Essential Headers: X-Forwarded-Host, X-Forwarded-For, X-Forwarded-Proto, X-Real-IP are set for Odoo's Proxy Mode.
    • Note on X-Real-IP: If using Cloudflare, X-Real-IP $remote_addr; might pass Cloudflare's IP. For the actual client IP, it's often better to use proxy_set_header X-Real-IP $http_cf_connecting_ip; if Cloudflare is sending that header, or use Nginx's real_ip module. However, the provided config is standard without Cloudflare specifics.
  • WebSocket Headers (Upgrade, Connection): These are correctly included in the location /longpolling block.
  • proxy_http_version 1.1;: This is CRUCIAL for Nginx when proxying WebSockets, ensuring the HTTP/1.1 protocol upgrade works correctly. This is a common fix for real-time issues.
  • Timeouts: proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout are set to 720s (12 minutes), which is generous and helps prevent premature disconnections for long-lived WebSocket connections.

Potential Minor Improvement for location /longpolling: The X-Forwarded-For and Host headers are already set in the main server block. While repeating them in location /longpolling is harmless, they are generally inherited. The Upgrade and Connection headers are the unique ones for this block.

"Do I need to adjust any Odoo settings for WebSockets to work properly?"

Yes, Odoo's odoo.conf needs to be correctly configured to work with this Nginx setup.

Assessment of Odoo odoo.conf settings:

  • http_port = 1700: This matches the odoo17 upstream in Nginx. Correct.
  • longpolling_port = 8072: This matches the odoo17chat upstream in Nginx. Correct.
  • proxy_mode = True: This is CRUCIAL for Odoo to correctly interpret the X-Forwarded-* headers from Nginx.
  • workers = 2: This enables multi-worker mode, which is good for production.
  • dbfilter = ^%h$: Correct for hostname-based multi-database setups.

Missing/Recommended Odoo Settings from your own troubleshooting journey (especially for Odoo 18):

Based on your recent successful troubleshooting, the following settings in odoo.conf are highly recommended for Odoo 18 stability and real-time performance:

  • Resource Limits:
    • limit_memory_hard = 2415919104 (e.g., ~2.25 GB per worker)
    • limit_memory_soft = 2013265920 (e.g., ~1.87 GB per worker)
    • limit_request = 8192
    • limit_time_cpu = 360
    • limit_time_real = 3600
    • limit_time_real_cron = 120 (Crucial for preventing cron timeouts)
  • WebSocket/Longpolling Specifics:
    • websocket_keep_alive_timeout = 600 (Helps maintain long-lived connections)
    • websocket_rate_limit_burst = 10
    • websocket_rate_limit_delay = 0.2
  • Session Storage (to prevent FileNotFoundError):
    • session_store = db (You already have this)
    • session_dir = False (Crucial to add, prevents Odoo from trying to write session files to disk when using session_store = db)
  • XML-RPC Configuration (for external integrations):
    • xmlrpc = True
    • xmlrpc_interface = 0.0.0.0
    • xmlrpc_port = 8069
    • xmlrpcs = True
    • xmlrpcs_interface = 0.0.0.0
    • xmlrpcs_port = 8071
 This worked for me!
                        
[options]
admin_passwd = ############
addons_path = /mnt/extra-addons,/usr/lib/python3/dist-packaes/odoo/addons
session_store = db
session_dir = False
limit_memory_hard = 2415919104
limit_memory_soft = 2013265920
limit_request = 8192
limit_time_cpu = 360
limit_real_time = 3600
limit_time_real_cron = 120
longpolling_port=8072
;logfile = /var/log/odoo/odoo-server.log
;logrotate = True
;log_level = debug
http_port =
;http_timeout = 1800
max_cron_threads = 2
workers = 5
websocket_keep_alive_timeout = 600
websocket_rate_limit_burst = 10
websocket_rate_limit_delay = 0.2
xmlrpc = True
xmlrpc_interface =
xmlrpc_port = 8069
xmlrpcs = True
xmlrpcs_interface =
xmlrpcs_port = 8071
proxy_mode = True
dbfilter = ^%h$

Conclusion:

The Nginx configuration is well-structured for longpolling. The Odoo odoo.conf is also good, but adding the specific limit_ and websocket_ parameters (especially session_dir = False and limit_time_real_cron) from your recent Odoo 18 troubleshooting will significantly improve stability and ensure real-time chat functions reliably.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
may 25
1426
1
jul 23
3551
0
abr 21
3413
2
sept 24
2266
1
may 24
3458