Odoo Help


Load Balancer with two Odoo instances leads to infinite loop

on 5/15/15, 5:08 AM 4,913 views

We created a setup with a load balancer (nginx) and two odoo instances. The load balancer has to distribute the requests equally to both instances to reduce the load.

see Image of simplified configuration 

If we use the normal load balancing configuration of nginx and only one user is accessing the web address this leads to an infinite redirection loop between these two instances during the login.

Does anyone know a solution for this loop of redirections?

Currently we set the option ip_hash in nginx. So all requests of the user are forwarded to the same node. But this is not our goal because this setup is used from a office which has only one IP and so all requests are forwarded to the same node and only one node gets the requests.

Used (minified) Nginx Configuration:

upstream balancer {
# ip_hash;
server alpha:8069;
server beta:8069;

server {
listen 443;
ssl on;

location / {
proxy_next_upstream http_500 http_502 http_503 http_504 timeout error invalid_header;
proxy_pass http://balancer;
proxy_read_timeout 300;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Url-Scheme $scheme;
proxy_redirect off;

Can you provide an example of your config file for nginx?

Aristóbulo Meneses
on 5/18/15, 4:23 AM
André Pereira
On 5/19/15, 4:15 AM

Have you tried the "sticky" option on your Nginx config? http://nginx.org/en/docs/http/ngx_http_upstream_module.html#sticky

It allows you to keep a user connecting to the same Odoo server without having to be tied to a specific IP. It distributes them randomly on the first connection, then uses a cookie to keep them on the same server.

Aristóbulo Meneses
On 5/18/15, 6:11 AM

Everything looks ok AFAIK, I think you should keep ip_hash parameter, because if an user logs into alpha and then balancer takes it over beta, it will loose its session and will have to login again.

I did it before (balancer) using ten instances and the only difference I see with your config is that I was not using https and I used weight for some of the servers. Maybe you should check this https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing-with-ssl-termination it might be useful


Daniel Reis

--Daniel Reis--
| 7 8 9
Linda-a-Velha, Portugal
--Daniel Reis--

Author of the "Odoo Development Essentials" book.

Applications Manager at Securitas Portugal

Github: https://github.com/dreispt

Twitter; @reis_pt

Daniel Reis
On 5/15/15, 5:55 AM

Probably you are complicating: Odoo provides load balancing out of the box, you should try that before other more complex alternatives.

To activate it just set the "workers" option of your config file to a non-zero number. For documentation on this see: https://www.odoo.com/documentation/8.0/setup/deploy.html#builtin-server

Your nginx would work as a simple reverse proxy, with no load balancing. It can still be useful to provide HTTPS and to cache static content, avoiding that extra load on the Odoo workers.

I know what workers are and we use this workers. We have two odoo servers for the failover. So we use nginx to balance the requests to both servers. Because we have already two servers it would be good to use both servers at the same time to reduce the load of the first server.

on 5/18/15, 5:55 AM

OK, the question mentioned "odoo instances", so it was not clear that you were using two servers.

Daniel Reis
on 5/18/15, 6:07 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)


Asked: 5/15/15, 5:08 AM
Seen: 4913 times
Last updated: 8/22/17, 1:26 PM