Upstream hash by multiple criteria

Kamil Gorlo kgorlo at gmail.com
Tue Jul 12 11:22:06 MSD 2011


Hello,

I am using ngx_http_upstream_hash_module for balancing requests to backend,
is there any way to balance by two or more variables, not one?

I want to write something like this:

upstream backend {
     hash $http_x_user $arg_user;
     server some_backend_1:8080;
     server some_backend_2:8080;
}

Semnatics is as follows:
 - if there is x-user header in request use it to calculate hash and
go to backend connected with calculated hash
 - it there is no x-user header look at query string, if there is user
field in query string calculate hash based on it

Is it possible? Or maybe it is easier with
ngx_http_upstream_consistent_hash (which even will be preferable)?

Cheers,

--
Kamil Gorlo



More information about the nginx mailing list