Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to split traffic from same url path to 2 different upstreams?

i have these upstreams declared:

upstream upstream_1 {
    server some_container_1:8000;
}

upstream upstream_2 {
    server some_container_2:8001;
}

and this server:

server {
    listen       7000;
    server_name  localhost;
    location /path {
        uwsgi_pass  upstream_1;
    }
}

where both some_container_1 and some_container_2 are based on same image (thus offer the same apis on the same paths) but differ on env vars and other non related stuff. i want to fork 1% of all traffic from localhost:7000/path to be delivered ‘as is’ to upstream_2 and 99% to remain on upstream_1. both cases should keep the request as received, altering neither path nor headers

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

with split_clients i can fork which path will be set before forwarding the request to a single upstream, which is not my case.

here the fork is done inside an upstream between servers, not inside a location splitting between upstreams, as i need.

can i define an upstream of upstreams like

upstream compound_upstream_1 {
    upstream upstream_1 weight=99;
    upstream upstream_2;
}

to use it on

server {
    listen       7000;
    server_name  localhost;
    location /path {
        uwsgi_pass  compound_upstream_1;
    }

is it possible to do this with nginx? considering so, which way should be the standard to accomplish this?

>Solution :

I don’t understand, what stops you from using server names in the upstream block directly?

upstream compound_upstream_1 {
    server some_container_1:8000 weight=99;
    server some_container_2:8001;
}
server {
    listen       7000;
    server_name  localhost;
    location /path {
        uwsgi_pass  compound_upstream_1;
    }
}

Or maybe I misunderstand your question?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading