[Seaside] Worker images with nginx and URL hash for sticky sessions

Levente Uzonyi leves at elte.hu
Sat Oct 25 02:00:30 UTC 2014


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
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>


More information about the seaside mailing list