PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

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

 September 01, 2022     nginx, nginx-location, nginx-reverse-proxy, nginx-upstreams     No comments   

Issue

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

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?



Answered By - Ivan Shatsky
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing