load balancing according to url

ESWAR RAO eswar7028 at gmail.com
Mon Apr 29 06:27:55 UTC 2013

Hi All,

Can anyone please help me with the below requirement.

Host machine contains a plugin and it communicates with a plugin handler
running on backend servers and nginx is used to load balance the requests.

host machine(plugin) ===== >nginx as load balancer =====>3 backend servers
which hosts plugin handler

I need to load balance the requests based on customer-id field in host
# curl '

customer-id: 123456789999999999
customer-id changes with customers.

Since the requests come from same machine, I can't use ip_hash or cookie
based load balancing technique.

My requirement is to load balance according to customer id and if same
request comes the same customer it should go to same earlier server which
served the request.

I am planning to extract the customer-id in nginx configuration file and
add them on the fly in the config file and compare the ids using "map"
directive. But unable to know which server served the requests to

map $customer_id $sticky_backend {
   default bad_gateway;
   <cust-id_1> <server 1>;
   <cust-id_2> <server 2>;
 if ( $request_uri ~ ^/(.*)/(customer)/(.*?)/(.*)/ ) {
   set $customer_id $3;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20130429/83bd9d19/attachment.html>

More information about the nginx mailing list