Common Nginx Error Log Pattern (Odoo 16/17+ WebSocket)
When upstream sockets, timeouts, body limits, or Docker DNS rules are misconfigured for Odoo 16/17+ WebSocket, Nginx typically records an entry matching the log line below inside /var/log/nginx/error.log:
2026/11/28 11:42:08 [error] 4120#4120: *1804 upstream prematurely closed connection while reading response header from upstream, client: 198.51.100.44, server: erp.example.com, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:8069/websocket", host: "erp.example.com"
Reverse Proxy Architecture & Header Forwarding for Odoo 16/17+ WebSocket
Starting with Odoo 16 and continuing through Odoo 17 and 18, Odoo replaced legacy HTTP /longpolling bus requests with a native WebSocket endpoint served at /websocket on the dedicated gevent worker port (8072 by default). Routing all traffic solely to the main HTTP worker on 127.0.0.1:8069, or copying older Odoo 15 /longpolling Nginx templates, breaks Discuss live chat, POS real-time sync, and instant chatter notifications with immediate WebSocket handshake failures.
Even when /websocket is pointed to port 8072, three default Nginx behaviors still break Odoo real-time connections: Nginx defaults to HTTP/1.0 upstream requests, strips the hop-by-hop Upgrade and Connection headers, and enforces a 60-second proxy_read_timeout. Because Odoo browser sessions keep idle WebSocket channels open between chatter updates, Nginx forcefully terminates the socket every 60 seconds, flooding the Odoo UI with "Real-time connection lost" banners.
A production-hardened Nginx reverse proxy for Odoo splits traffic across two explicit upstreams: standard web and XML-RPC/JSON-RPC requests under location / forward to 127.0.0.1:8069, while location /websocket proxies directly to 127.0.0.1:8072 with proxy_http_version 1.1, Upgrade $http_upgrade, Connection "upgrade", X-Forwarded-Proto $scheme, and proxy_read_timeout 720s (matching Odoo long-lived worker timeouts).
Always pair the Nginx server block with proxy_mode = True and workers > 0 in /etc/odoo/odoo.conf. Without proxy_mode = True, Odoo ignores X-Forwarded-Proto and generates plain http:// asset and OAuth callback URLs; without multiprocessing workers enabled, Odoo never binds the gevent port 8072 at all.
- Running Odoo inside Docker containers behind Nginx? Configure dynamic upstream resolution with our Docker Compose Nginx 127.0.0.11 upstream proxy guide so container restarts never trigger 502 Bad Gateway.
- If you host multiple internal routes alongside /websocket on one domain, review our Nginx multi-service subpath routing configuration to avoid overlapping location blocks.
- For mixed HTTP/1.1 and wss:// traffic on TLS 443, see the Nginx WSS reverse proxy $connection_upgrade map setup.
Step-by-Step Nginx & Odoo 16/17+ WebSocket Deployment Guide
Apply the Nginx server block above alongside these upstream framework trust-proxy settings so HTTPS detection, real client IPs, and reload safety work reliably in production.
1Broken Pattern vs. Hardened Nginx Block for Odoo /websocket (8072) and / (8069)
/etc/nginx/sites-available/erp.example.com.confDo not send /websocket to port 8069 or keep legacy /longpolling blocks on Odoo 16/17+. Define separate upstreams for Odoo HTTP (8069) and gevent WebSocket (8072), with HTTP/1.1 Upgrade headers and 720s read/send timeouts.
/etc/nginx/sites-available/erp.example.com.confnginx# BROKEN PATTERN (drops Odoo 16/17+ live chat & bus notifications): # location / { proxy_pass http://127.0.0.1:8069; } # Missing /websocket -> 8072, Upgrade headers, and 720s timeout upstream odoo_http { server 127.0.0.1:8069; } upstream odoo_gevent { server 127.0.0.1:8072; } server { listen 443 ssl http2; server_name erp.example.com; proxy_read_timeout 720s; proxy_connect_timeout 720s; proxy_send_timeout 720s; client_max_body_size 100M; location /websocket { proxy_pass http://odoo_gevent; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $http_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; proxy_read_timeout 720s; proxy_buffering off; } location / { proxy_pass http://odoo_http; proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $http_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; proxy_redirect off; } }2Enable proxy_mode and Gevent Multiprocessing Workers in odoo.conf
/etc/odoo/odoo.confOdoo only spawns the evented gevent server on port 8072 when workers is greater than 0. Set proxy_mode = True so Odoo trusts Nginx X-Forwarded-Proto and X-Forwarded-For headers.
/etc/odoo/odoo.confnginx[options] proxy_mode = True http_interface = 127.0.0.1 http_port = 8069 gevent_port = 8072 workers = 4 limit_time_cpu = 600 limit_time_real = 12003Verify Port 8072 Listener and Test Live WSS Upgrade Handshake
terminal (Ubuntu / Debian)Confirm Odoo is listening on both 8069 and 8072, validate Nginx syntax before reloading, and test that /websocket responds with HTTP 101 Switching Protocols.
terminal (Ubuntu / Debian)bashss -tlnp | grep -E "8069|8072" sudo nginx -t && sudo systemctl reload nginx curl -i -N \ -H "Connection: Upgrade" \ -H "Upgrade: websocket" \ -H "Sec-WebSocket-Version: 13" \ -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \ https://erp.example.com/websocket
Common Odoo 16/17+ WebSocket Nginx Reverse Proxy Pitfalls
Review these three production failure modes before reloading Nginx on staging or live servers.
Using Outdated Odoo 15 /longpolling Rules on Odoo 16, 17, or 18
Odoo 16 renamed longpolling_port to gevent_port and moved real-time bus traffic from /longpolling to /websocket. Leaving only location /longpolling in Nginx sends /websocket requests to port 8069, where standard HTTP workers reject the WebSocket upgrade.
Forgetting workers > 0 in odoo.conf (Connection Refused on Port 8072)
When workers = 0 (Odoo threaded development mode), Odoo does not start the separate gevent process on port 8072. Nginx immediately logs 502 Bad Gateway with "connect() failed (111: Connection refused) while connecting to upstream 127.0.0.1:8072".
Leaving Default 60-Second proxy_read_timeout on /websocket
Idle Odoo browser tabs trigger Nginx upstream read timeouts every 60 seconds unless proxy_read_timeout is raised (720s or higher). Repeated reconnect loops spike PostgreSQL bus queries and display "Real-time connection lost" warnings to users.
Complete Your Deployment With Matching Docker Compose & CORS Tools
Pair this Nginx reverse proxy block with healthcheck-gated Docker Compose orchestration and verified browser CORS headers:
Deploy FastAPI, PostgreSQL 16, and Nginx on a Linux VPS with Docker Compose using pg_isready healthchecks, 127.0.0.1 firewall safety, and zero-downtime reloads.
Fix duplicate Access-Control-Allow-Origin headers and 403 OPTIONS preflight failures when proxying a Docker API behind Nginx. Copy working config.
Frequently Asked Questions
- Why does Odoo 16/17+ WebSocket return 502 Bad Gateway on port 8072 behind Nginx?
- Port 8072 only binds when Odoo runs in multiprocessing mode (workers >= 2) with gevent_port = 8072 in odoo.conf. Verify with ss -tlnp | grep 8072 and restart the odoo service after setting workers.
- Should Nginx proxy /websocket to 127.0.0.1:8069 or 127.0.0.1:8072?
- In production multiprocessing deployments, proxy /websocket exclusively to 127.0.0.1:8072 (the gevent worker) and regular HTTP traffic under / to 127.0.0.1:8069. Keeping long-lived sockets isolated on gevent prevents starving regular HTTP worker threads.
- Why are Odoo PDF reports and portal links generating http:// URLs instead of https://?
- You must set proxy_mode = True in odoo.conf and send proxy_set_header X-Forwarded-Proto $scheme; from Nginx. Without both settings, Odoo treats proxied requests as plain HTTP.
Related Nginx Reverse Proxy Guides
Browse all 13 Nginx guides →Nginx WSS Reverse Proxy & $connection_upgrade Map Config (TLS 443)
Build a TLS 443 Nginx wss:// reverse proxy using map $http_upgrade $connection_upgrade, proxy_http_version 1.1, and 3600s read/send timeouts.
Nginx Reverse Proxy Config for Socket.IO & WebSockets (Upgrade & 3600s)
Fix WebSocket 400 errors and 60-second disconnects in Nginx for Socket.IO and ws servers. Generate Upgrade, Connection map, and 3600s proxy_read_timeout blocks.
Nginx Reverse Proxy for Docker Compose Services (127.0.0.11 DNS Resolver)
Fix 502 Bad Gateway and Nginx startup crashes in Docker Compose using resolver 127.0.0.11 and dynamic variable proxy_pass across container restarts.