Odoo Help

Welcome!

This community 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.

1

Load Balancer with two Odoo instances leads to infinite loop

By
Christoph
on 5/15/15, 5:08 AM 2,305 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
1
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.

1
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

1

Daniel Reis

--Daniel Reis--
3436
| 6 7 9
Lisbon, 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.

Christoph
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 5/15/15, 5:08 AM
Seen: 2305 times
Last updated: 8/11/16, 7:42 AM