Skip to main content

How to Configure NginX Reverse Proxy for Odoo

In this article, I will guide you through the process of configuring Odoo with NginX as a reverse proxy. Using NginX with Odoo is an efficient way to improve performance and security by better handling both HTTP and WebSocket connections.

Configuring Odoo

Before configuring NginX, you need to make sure that Odoo is properly configured to handle both HTTP and WebSocket connections. As of version 16, Odoo includes support for WebSocket, which means that this feature is automatically enabled when you enable multiple workers in the Odoo configuration file.

Odoo configuration example (`odoo-server.conf`)

[options]
http_port = 8069

# Parallel workers (2 * Cpu Cores + 1)
workers = 9

In this configuration, Odoo uses port 8069 for HTTP and manages workers to optimize load on servers with multiple CPU cores.

Virtual Host NginX Odoo

Now that Odoo is configured, we can configure NginX as a reverse proxy. This allows NginX to handle HTTP requests and forward them to Odoo on port 8069. In addition, NginX can handle WebSocket connections needed for some advanced Odoo features, such as real-time notifications.

NginX configuration example

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

upstream odoo {
    server 127.0.0.1:8069;
}

upstream odoomp {
    server 127.0.0.1:8072;
}

server {
    listen 443 ssl;
    server_name SERVERNAME.TLD;
    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;
    location / {
        proxy_pass http://odoo;
        proxy_redirect off;
    }
    location ~* /web/static/ {
        proxy_cache_valid 200 90m;
        proxy_buffering on;
        expires 864000;
        proxy_pass http://odoo;
    }
    # Redirects WebSocket requests to Odoo's gevent port.
    location /websocket {
        proxy_redirect off;
        proxy_pass http://odoomp;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        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;
    }
}

In this example, Odoo uses port 8069 to handle HTTP traffic and port 8072 for WebSocket connections. The NginX server handles both HTTP and WebSocket traffic, thus improving performance and simplifying the handling of requests.

Integration with SSL

To ensure greater security, it is essential to configure NginX with an SSL certificate. This allows traffic between the client and server to be encrypted, protecting sensitive data. You can obtain a free SSL certificate using Let's Encrypt by integrating it into your NginX configuration as shown above.

Try Our Free NGINX Technical Consulting

Optimize your Odoo configuration with our NginX Technical Support. Get a 30-minute free analysis now!

FAQ: Frequently Asked Questions

1. What is the advantage of using NginX as a reverse proxy for Odoo?

NginX offers more efficient resource management than Apache and allows you to handle concurrent connections with less CPU and RAM usage. This results in better scalability and performance for Odoo.

2. Do I need to manually configure WebSocket for Odoo?

No, Odoo 16 and later versions natively support WebSocket when enabling multiple workers. However, you must properly configure NginX to handle these connections, as explained in this article.

3. Can I use Let's Encrypt with NginX?

Yes, Let's Encrypt offers free SSL certificates that can be easily integrated with NginX. This allows you to encrypt communications between the client and server at no extra cost.

Try our free NginX technical consulting

Optimize your Odoo configuration with our NginX technical support. Now Free 30 minutes of analysis!

.

Add new comment

Comment

  • Allowed HTML tags: <br> <p> <code class="language-*"> <pre>
  • Lines and paragraphs break automatically.
  • Only images hosted on this site may be used in <img> tags.