# Upstream hash by multiple criteria

**URL:** <https://www.ruby-forum.com/t/upstream-hash-by-multiple-criteria/209342>\
**Category:** NGINX\
**Created:** [July 12, 2011, 9:23am UTC](https://www.ruby-forum.com/t/upstream-hash-by-multiple-criteria/209342 "2011-07-12T09:23:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 12, 2011, 9:23am UTC](https://www.ruby-forum.com/t/upstream-hash-by-multiple-criteria/209342/1 "2011-07-12T09:23:00Z")

</div>

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 G.
