Worker images with nginx and URL hash for sticky sessions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Worker images with nginx and URL hash for sticky sessions

Torsten Bergmann
Hi,

in nginx one can use for load balancing:

upstream seaside {
  ip_hash;
  server 127.0.0.1:8080;
  server 127.0.0.1:8081;
  ...
}

This is using the IP Hash method for balancing (http://nginx.com/products/application-load-balancing).

Any experience how to configure the more generic Hash method (based on user-defined key such as the URL) with nginx?

Similar to what is described for Apache: http://book.seaside.st/book/advanced/deployment/deployment-apache/mod-proxy-balancer
but for nginx?

Thx
T.

 
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Worker images with nginx and URL hash for sticky sessions

Esteban A. Maringolo
I'm interested in this as well.

ip_hash is the simplest solution, but has it's shortcomings if a good
part of the users are corporate going out to internet from the same IP
address (which is my case).


Regards!
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Worker images with nginx and URL hash for sticky sessions

Levente Uzonyi-2
In reply to this post by Torsten Bergmann
Here's how I would do it based on the cookie named backend:
- create a generic upstream with all your backends
- create specific upstreams for each of your backends
- create a map based on the cookie value (you can use any variable here,
not just cookies if you want to) which will select the sticky upstream,
and defaults to the generic upstream.

For example:

upstream generic {
  server 127.0.0.1:8081;
  server 127.0.0.1:8082;
  server 127.0.0.1:8083;
}

upstream sticky8081 {
  server 127.0.0.1:8081;
}

upstream sticky8082 {
  server 127.0.0.1:8082;
}

upstream sticky8083 {
  server 127.0.0.1:8083;
}

map $cookie_backend $sticky_backend {
  default generic;
  "1" sticky8081;
  "2" sticky8082;
  "3" sticky8083;
}

your proxy_pass directive will be

...
proxy_pass http://$sticky_backend;
...

When you create a new session, you set the backend cookie with the value
assigned to your backend (1, 2 or 3 in this example), and further requests
will be proxied to that backend.

If you don't want to use cookies, then any nginx variable should work. For
example an url parameter named backend would be:

map $arg_backend $sticky_backend {
...

or the request url:

map $uri $sticky_backend {
... (note that you can use regular expressions here)


Levente

On Fri, 24 Oct 2014, Torsten Bergmann wrote:

> Hi,
>
> in nginx one can use for load balancing:
>
> upstream seaside {
>  ip_hash;
>  server 127.0.0.1:8080;
>  server 127.0.0.1:8081;
>  ...
> }
>
> This is using the IP Hash method for balancing (http://nginx.com/products/application-load-balancing).
>
> Any experience how to configure the more generic Hash method (based on user-defined key such as the URL) with nginx?
>
> Similar to what is described for Apache: http://book.seaside.st/book/advanced/deployment/deployment-apache/mod-proxy-balancer
> but for nginx?
>
> Thx
> T.
>
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Worker images with nginx and URL hash for sticky sessions

Dave
In reply to this post by Torsten Bergmann
Hi Torsten,
I approached sticky sessions some time ago. There is a module on nginx you can use: https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/overview

but you have to recompile nginx from source. You can also have to pay attention at the nginx path, I don't remember exaclty, but when compiling from source, nginx is installed in /opt instead of /etc

Cheers
Dave

Torsten Bergmann wrote
Hi,

in nginx one can use for load balancing:

upstream seaside {
  ip_hash;
  server 127.0.0.1:8080;
  server 127.0.0.1:8081;
  ...
}

This is using the IP Hash method for balancing (http://nginx.com/products/application-load-balancing).

Any experience how to configure the more generic Hash method (based on user-defined key such as the URL) with nginx?

Similar to what is described for Apache: http://book.seaside.st/book/advanced/deployment/deployment-apache/mod-proxy-balancer
but for nginx?

Thx
T.

 
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Worker images with nginx and URL hash for sticky sessions

Johan Brichau-2
In reply to this post by Torsten Bergmann
I’m using this [1] but, as you can see, it’s obsolete since nginx 1.7.2 (so I will be switching soon to the built-in hash).
A bit more info on why here [2].

[1] http://wiki.nginx.org/HttpUpstreamRequestHashModule
[2] http://jbrichau.github.io/blog/when-to-use-http-session-affinity-in-glass/

> On 24 Oct 2014, at 23:53, Torsten Bergmann <[hidden email]> wrote:
>
> Hi,
>
> in nginx one can use for load balancing:
>
> upstream seaside {
>  ip_hash;
>  server 127.0.0.1:8080;
>  server 127.0.0.1:8081;
>  ...
> }
>
> This is using the IP Hash method for balancing (http://nginx.com/products/application-load-balancing).
>
> Any experience how to configure the more generic Hash method (based on user-defined key such as the URL) with nginx?
>
> Similar to what is described for Apache: http://book.seaside.st/book/advanced/deployment/deployment-apache/mod-proxy-balancer
> but for nginx?
>
> Thx
> T.
>
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside