Welcome! Log In Create A New Profile

Advanced

Use of Variables in Upstream hash Session Persistance

Posted by sampipe 
Use of Variables in Upstream hash Session Persistance
April 15, 2019 12:35AM
Hi,

Lets say I have 1 x nginx front end servers which load balances to 2 x app server and requires session persistence.

I can set up an upstream group like this.

upstream backend {

hash $request_uri consistent;
server backend1;
server backend2;
}

If the requests always have a HTTP header called say "x-user-name", I was hoping that I could do this:

hash $http_x_user_name consistent;

but it doesn't seem to work for me..

Does anyone know if this should work? or what variables are available in the upstream context?

I've tried $sent_http_x_user_name and also $upstream_http_x_user_name also.

Would appreciate any help!

Sam
Re: Use of Variables in Upstream hash Session Persistance
April 17, 2019 02:00AM
Seems this does work .. removing the consistent from the hash ensures it balances better. I put nginx into debug and the output showed it working.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 214
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready