Configure Odoo with Nginx as a Reverse Proxy

Introduction

Before we begin talking about configure Odoo with Nginx as a Reverse Proxy, let's briefly understand – What is Odoo ?

Odoo is a versatile business application suite that automates processes. It provides tools for various activities such as accounting, inventory management, marketing, sales, and more. With its user-friendly interface and customizable features, Odoo streamlines business operations, increases efficiency, and improves productivity.

The versatility of Odoo allows it to cater to the needs of businesses of all sizes and industries. Embrace Odoo and experience a powerful solution that simplifies your business management tasks.

In this tutorial, you will configure Odoo with Nginx as a Reverse Proxy. We will also address a few FAQs on how to configure Odoo with Nginx as a Reverse Proxy.

Advantages of Odoo

  1. Versatility: Odoo offers a comprehensive suite of applications to streamline various business activities.
  2. Customization: It is highly customizable, allowing businesses to adapt and personalize it according to their specific needs.
  3. Integration: Odoo seamlessly integrates different modules, ensuring smooth data flow and eliminating the need for multiple software systems.
  4. User-friendly: Its intuitive interface makes it easy to use for employees at all levels, reducing training time and increasing adoption.
  5. Cost-effective: Odoo's open-source nature makes it an affordable solution compared to proprietary software, enabling businesses to save on licensing fees.

Prerequisites

Before proceeding with this tutorial, please ensure that you have met the following prerequisites:

  • You have Odoo installed, if not, instructions can be found here.
  • You've got a domain name that points to your Odoo installation. We will use odoo.example.com in this tutorial.
  • If you do not have Nginx installed, see this tutorial.
  • Your domain has an SSL certificate installed. Follow this tutorial to install a free Let's Encrypt SSL certificate.

Configure Nginx as a Reverse Proxy

Load balancing, SSL termination, caching, compression, serving static content, and other advantages come with using a reverse proxy.

In this example, we'll set up SSL termination, HTTP to HTTPS redirection, static file caching, and GZip compression.

A sample nginx configuration file (server block) for your Odoo installation is provided below. All HTTP requests will be routed to HTTPS.

Create the following file in your text editor:

sudo nano /etc/nginx/sites-enabled/odoo.example.com
upstream odoo {
 server 127.0.0.1:8069;
}

upstream odoo-chat {
 server 127.0.0.1:8072;
}

server {
    server_name odoo.example.com;
    return 301 https://odoo.example.com$request_uri;
}

server {
   listen 443 ssl http2;
   server_name odoo.example.com;

   ssl_certificate /path/to/signed_cert_plus_intermediates;
   ssl_certificate_key /path/to/private_key;
   ssl_session_timeout 1d;
   ssl_session_cache shared:SSL:50m;
   ssl_session_tickets off;

   ssl_dhparam /path/to/dhparam.pem;

   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
   ssl_prefer_server_ciphers on;

   add_header Strict-Transport-Security max-age=15768000;

   ssl_stapling on;
   ssl_stapling_verify on;
   ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;
   resolver 8.8.8.8 8.8.4.4;

   access_log /var/log/nginx/odoo.access.log;
   error_log /var/log/nginx/odoo.error.log;

   proxy_read_timeout 720s;
   proxy_connect_timeout 720s;
   proxy_send_timeout 720s;
   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;

   location / {
     proxy_redirect off;
     proxy_pass http://odoo;
   }

   location /longpolling {
       proxy_pass http://odoo-chat;
   }

   location ~* /web/static/ {
       proxy_cache_valid 200 90m;
       proxy_buffering    on;
       expires 864000;
       proxy_pass http://odoo;
  }

  # gzip
  gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
  gzip on;
}

Remember to replace odoo.example.com with your Odoo domain and to specify the correct path for the SSL certificate files.

When finished, save the file and restart the Nginx service with the following command:

sudo systemctl restart nginx

Change the Binding Interface

This is an optional step, but it is a good security precaution.

Odoo server listens on port 8069 on all interfaces by default. To prevent direct access to your Odoo instance, open the Odoo configuration file and add the following two lines at the end of the file:

xmlrpc_interface = 127.0.0.1
netrpc_interface = 127.0.0.1

For the modifications to take effect, save the configuration file and restart the Odoo server:

systemctl restart odoo

FAQs to Configure Odoo with Nginx as a Reverse Proxy

How do I install Nginx? 

Nginx can be easily installed on various operating systems. Detailed instructions can be found on the official Nginx website or the Odoo documentation.

What are the benefits of using Nginx as a reverse proxy for Odoo? 

Nginx provides SSL termination, load balancing, caching, and IP filtering capabilities, improving the overall performance and security of your Odoo setup.

Can I configure multiple Odoo instances behind Nginx?

Yes, Nginx enables you to configure multiple Odoo instances on the same server using different ports or domain names.

How do I configure Nginx as a reverse proxy for Odoo? 

Detailed instructions can be found in the Odoo documentation, which includes step-by-step guides for various versions of Odoo and Nginx configurations.

Does configuring Nginx as a reverse proxy require advanced technical skills? 

Basic knowledge of Linux, Nginx, and Odoo config files is helpful, but the process is well-documented and achievable with proper guidance.

Can I use a different web server instead of Nginx? 

While Nginx is recommended, other web servers like Apache can also be used as a reverse proxy. However, the configuration process might differ.

Is it necessary to configure Nginx as a reverse proxy for Odoo? 

It is not mandatory, but configuring Nginx enhances performance, security, and customization options, making it a recommended approach for production environments.

Conclusion

You learnt how to set up Nginx as a proxy for your Odoo application in this tutorial.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.