GoranStimac.com



How To Install Odoo 14 System and Set It to Work via Nginx Proxy

Set up an Ubuntu/Debian Linux server and connect to it via an SSH root user or run the command

sudo su

which will switch you to the root user so that they can execute command

apt update && sudo apt upgrade -y

Odoo uses PostgreSQL so we need to install it

apt install postgresql -y

To be able to create PDF documents using Odoo you need to install wkhtmltopdf, download it from the GitHub

wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb

Then you need to install the downloaded .deb package with a command similar to this, set the path to the directory where the wkhtmltopd package is located

apt install /home/user/wkhtmltox_0.12.6-1.focal_amd64.deb

Installing the Odoo System

We can now download and install Odoo using the official Ubuntu / Debian repository as root. During the installation, Odoo will retrieve everything else it needs

wget -O - https://nightly.odoo.com/odoo.key | apt-key add -
echo "deb http://nightly.odoo.com/14.0/nightly/deb/ ./" >> /etc/apt/sources.list.d/odoo.list
apt-get update && apt-get install odoo

The Odoo system can be started, stopped, and reset as a system service using the commands

sudo systemctl enable odoo
sudo systemctl restart odoo
sudo systemctl stop odoo
sudo systemctl start odoo

We now have an Odoo system that works via port 8069 which means we need to enter the ip address of the server e.g. 192.168.0.1:8069 to access it or an address like this example.com:8069.

Setting up an Nginx Proxy

Web applications typically run over port 80 for http and 443 for https protocols so a proxy should be set up in front of the Odoo system that will allow Odoo to run over these standard ports.

This is often done using a popular and small nginx proxy so let’s set it up

sudo apt install nginx

Now we need to complete the configuration, which is not a trivial task for most, so let’s start slowly. You must first enable proxy_mod in the Odoo configuration

sudo nano /etc/odoo/odoo.conf

add to file

proxy_mode = True

In the same file, we will set up the workers immediately to enable the longpolling port through which the chat works that need a permanent worker to work. At the start, the configuration is set to 0 workers, which is not zero, but it is automatically assigned, and the chat functionality does not work in this mode.

Here you need to calculate a little and plan to set things up correctly. Mathematics and theory go like this:

  • if we have, for example, 4 cores and 8 threads
  • you want to serve, for example, 60 users at a time
  • 60 users / 6 = 10 (which is the number of workers we theoretically need to have available to make things run smoothly)
  • (4 * 2) + 1 = 9 (theoretically the maximum number of workers for Odoo considering the number of cores we have)
  • Namely, we will use 8 workers + 1 worker for cron tasks and monitor the consumption of resources, which should be between 7 and 7.5, if it is less we can add workers, and if there is more we should reduce them.
  • In the end, we need to know how much RAM we need for which we will use the formula RAM = 9 * (0.8 * 150) + (0.2 * 1024)) which is approximately 3GB of RAM that we must have at least for normal operation of the Odoo system.

Now that we have calculated and figured out how much we can set up, let’s complete the configuration:

[options]
limit_memory_hard = 1677721600
limit_memory_soft = 629145600
limit_request = 8192
limit_time_cpu = 600
limit_time_real = 1200
max_cron_threads = 1
workers = 8

Next, you need to set up a proxy and update the Nginx configuration

sudo nano /etc/nginx/sites-available/default

First you need to create groups for two important Odoo ports. The first is for the system itself

upstream odoo {
   server 127.0.0.1:8069;
}

The second group is for the port that Odoo uses for chat functionality

upstream odoochat {
   server 127.0.0.1:8072;
}

Then we want everything to work via the https protocol for which we need to have an SSL certificate that can be set using CertBot which I will skip because if you don’t know how to set SSL then don’t do this at all :/

# http -> https
server {
   listen 80;
   server_name example.com www.example.com;
   rewrite ^(.*) https://$host$1 permanent;
}

Don’t forget to enter your own in this and all other code examples instead of the example.com address.

Now comes the last largest block, which I will show in full and explain below:

server {
   listen [::]:443 ssl ipv6only=on;
   listen 443 ssl http2;
   server_name example.com www.example.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;
   # SSL parameters
   ssl on;
   ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
   ssl_certificate_key /etc/letsencrypt/example.com/privkey.pem; # managed by Certbot
   include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
   ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
   # Redirect longpoll requests to odoo longpolling port
   location /longpolling {
      proxy_pass http://odoochat;
   }
   # Redirect requests to odoo backend server
   location / {
      proxy_redirect off;
      proxy_pass http://odoo;
   }
   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;
}

So let’s start with a short and quick explanation of the above block of code

listen [::]:443 ssl ipv6only=on;
listen 443 ssl http2;
server_name example.com www.example.com;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;

To make things work faster we use the somewhat newer settings ipv6 and http2 if these first two lines make a problem can be summarized in one general

listen 443;

Other lines define the domains that will be used to run the application and limit the availability time of the proxy connection to make things work faster especially if a process happens to us that doesn’t want to close the connection without a limit we have a loss of resource.

#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;

For the application to work properly, we must forward its headers via a proxy, which this block does

#SSL parameters
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

This block is generated by CertBot automatically just needs to be left as is. You must use CertBot, this block cannot be placed in the configuration file just like that, because SSL will not work for you.

The next block connects the chat functionality and forwards it to the previously created group /longpolling

#Redirect longpoll requests to odoo longpolling port
location /longpolling {
   proxy_pass http://odoochat;
}

Then we have a block that connects the Odoo system to a previously created group

#Redirect requests to odoo backend server
location / {
   proxy_redirect off;
   proxy_pass http://odoo;
}

The next block is optional, but speeds up the operation and response of the Odoo system and uses Nginx cache mechanisms to make static Odoo system files serve faster with a 90-minute delay

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

If you want this block you can delete it completely.

Then we have a block that allows you to compress static files to serve them faster and define which files they are

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

If you have done everything well you have a fully functional Odoo system and you can move to the administrative interface of the Odoo system which allows you to do most of the work and a multitude of functionalities.

Also, Odoo now works via port 443 so all you have to do is just enter a domain or ip without a port.

Odoo is the best ERM and CRM system for small and medium-sized businesses and I hope I made it easier for you to set it up which unfortunately has never been easy…

Find more information at

Odoo 14 Setup

Odoo 14 Install

If you need help feel free to contact me.

Related Posts