I'm trying to figure out how to do some if-else logic in NGINX's upstream
load-balancing directive. Basically, I'd like to use the method:
hash $cookie_my_cookie_name consistent;
... if the cookie (my_cookie_name
) is present. If that cookie is not present, then I'd like the upstream selection method to fall-back to the built-in:
ip_hash;
I haven't been able to find examples anywhere in NGINX's docs on how to 'try' one upstream selection method and if that can't work select an alternative method.
The scenario I'm a but worried about is if the cookie isn't present, the $cookie_my_cookie_name
variable interpolates (at least in the logs) to -
, which is a string, but will always hash to the same upstream server, which is exactly what I don't want. (Thus the test needs to be for the absence of the cookie, which, if present, will always hold a 'good' value.)
Any ideas?