Nginx split_clients not dividing traffic

1.7k Views Asked by At

I have the following nginx.config file:

events {}

http {
    # ...
    # application version 1a 
    upstream version_1a {
        server localhost:8090;
    }

    # application version 1b
    upstream version_1b {
        server localhost:8091;
    }

    split_clients "${arg_token}" $appversion {
        50%     version_1a;
        50% version_1b;
    }

    server {
        # ...
        listen 7080;
        location / {
            proxy_set_header Host $host;
            proxy_pass http://$appversion;
        }
    }
}

I have two nodejs servers listening on port 8090 and 8091 and I am hitting the URL http://localhost:7080, my expectation here is the Nginx will randomly split the traffic to version_1a and version_1b upstream, but, all the traffic is going to version_1a. Any insight into why this might be happening?

(I want to have this configuration for the canary traffic)

2

There are 2 best solutions below

0
Vishrant On

Validate the variable you are using to split the traffic is set correctly, and the variable's value should be uniformly distributed else the traffic will not be split evenly.

0
Thomas On

I have the same problem with the following configuration:

upstream exercim {
    server host.docker.internal:8081;
}

upstream nutshell {
    server host.docker.internal:8082;
}

split_clients "${remote_addr}" $backend {
    50% exercim;
    *   nutshell;
}

server {
    listen       80 default_server;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location /exercim/ {
        proxy_pass  http://$backend;
    }

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}

$remote_addr contains an IP address.

Still the traffic is not split.