3

We are using nginx for load balancing. We just pushed a new server online with a massive upgrade to our platform for testing before we roll it out. We want to make sure it's working for, so we have weights set to send roughly 10% of the traffic to that server.

The problem is that we need to ensure that if the user is servers that server, they will always get that server for future sessions. This is easily done with ip_hash, but what we really want is for the other services to use a round-robin strategy while ONLY that one server uses ip_hash.

Is something like that possible at all? Here is our upstream.conf

upstream apps  {
   ip_hash;
   server 10.134.13.38:80 weight=3; # app-00
   server 10.134.13.46:80 weight=3; # app-01
   server 10.134.24.30:80 weight=3; # app-02
   server 10.134.8.153:80 weight=1; # app-new-test
}
2

I would use split_clients directive and define two upstreams.

upstream apps {
   server 10.134.13.38:80; # app-00
   server 10.134.13.46:80; # app-01
   server 10.134.24.30:80; # app-02
}

upstream apps_new_test {
   server 10.134.8.153:80; # app-new-test
}

split_clients "${remote_addr}AAA" $upstream_app {
    10% apps_new_test;
    *   apps;
}

server {
    ...
    proxy_pass http://$upstream_app;
}
  • This is great. After nginx serves either apps or apps_new_test, is it sticky so that that user will always get that same upstream? – JoshL Sep 22 '17 at 21:23
0

There is a single request distribution policy in use for a single upstream block. So, you cannot achieve your goal like this.

You could try something like assigning a cookie for users coming to the app-new-test server. The cookie assignment would be done by the new app running on the server.

Then you would test for that cookie value in server block with if directive, and then use proxy_pass http://10.134.8.153;. For example:

server {
    if ($cookie_upstream = "app-test-new") {
        proxy_pass http://10.134.8.153;
    }
    proxy_pass http://apps;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.