This question has been flagged
7 Replies
20613 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;
}
}

Avatar
Discard

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

Best Answer

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.

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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.

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

Best Answer

I noticed you have IP_hash commented out.  We have 6 Front End servers running using ip_hash in nginx, without any nginx related issues.  Don't forget the longpolling upstream to do the same.  The only difference is I used the local ip, vs the server name. But same principal.

upstream balancer {
# ip_hash;
server alpha:8069;
server beta:8069;
}
Avatar
Discard