Nginx Reverse Proxy Builder · Odoo 16/17+ WebSocket

Nginx Reverse Proxy for Odoo WebSockets (/websocket on Port 8072)

Generate an Nginx reverse proxy server block for Odoo 16/17+ WebSocket with URL prefix rewrite previews, Certbot SSL redirects, WebSocket upgrade headers, and Docker DNS checks.

Written & verified by Chathura Prabashana · Updated November 2026

1. Adjust stack settings or load a test scenario2. Inspect live diagnostics3. Copy generated config
Quick-Test Scenarios:

1. Domain, Routing & Upstream

2. TLS, WebSockets & Directives

# /etc/nginx/sites-available/erp.example.com.conf
# Generated by OpsCheck DevTools — Validate with: sudo nginx -t && sudo systemctl reload nginx

# Required in http {} context (or top of sites-available file) for clean WebSocket upgrades
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80;
    listen [::]:80;
    server_name erp.example.com;

    # Redirect all plaintext HTTP traffic permanently to HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name erp.example.com;

    # Let's Encrypt Certbot TLS Certificates
    ssl_certificate     /etc/letsencrypt/live/erp.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/erp.example.com/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    client_max_body_size 100M;

    # Gzip compression for JSON, JS, CSS, and SVG responses
    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 5;
    gzip_min_length 1024;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;

    # Baseline HTTP Security Headers
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    location /websocket {
        proxy_pass http://127.0.0.1:8072;
        proxy_http_version 1.1;
        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 X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Port $server_port;

        # WebSocket & Upgrade support (requires map $http_upgrade $connection_upgrade)
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_cache_bypass $http_upgrade;

        proxy_connect_timeout 15s;
        proxy_send_timeout 3600s;
        proxy_read_timeout 3600s;
    }
}
$sudo nginx -t && sudo systemctl reload nginx
URL Routing TransformationPrefix Preserved
GET https://erp.example.com/websocket/usershttp://127.0.0.1:8072/websocket/users

Strip Prefix OFF: Nginx preserves the full URI so upstream receives '/websocket/users'.

Configuration Diagnostics

  • infoPrefix Preserved (/websocket Forwarded Intact)

    GET https://erp.example.com/websocket/users -> Upstream receives http://127.0.0.1:8072/websocket/users. Strip Prefix OFF: Nginx preserves the full URI so upstream receives '/websocket/users'.

  • passWebSocket Upgrade & Extended Timeout (3600s) Enabled

    Configured HTTP/1.1 Upgrade, Connection $connection_upgrade map, and extended proxy_read_timeout for persistent real-time sockets.

  • infoSingle-Layer CORS Policy Reminder

    This configuration intentionally omits Access-Control-Allow-Origin headers so your upstream backend framework (Laravel, FastAPI, Express, ASP.NET Core) owns CORS cleanly without duplicate header rejections.

Runs locally in your browser. Domain names and upstream topology are never sent to a server.

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:

/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.

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.

  1. 1Broken Pattern vs. Hardened Nginx Block for Odoo /websocket (8072) and / (8069)

    /etc/nginx/sites-available/erp.example.com.conf

    Do 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;
        }
    }
  2. 2Enable proxy_mode and Gevent Multiprocessing Workers in odoo.conf

    /etc/odoo/odoo.conf

    Odoo 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 = 1200
  3. 3Verify 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)bash
    ss -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.

Pitfall 1

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.

Pitfall 2

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".

Pitfall 3

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.

Related Tools

Pair this Nginx reverse proxy block with healthcheck-gated Docker Compose orchestration and verified browser CORS headers:

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.
Browse all 13 Nginx guides →