I’ve fundamental nginx load-balancing setup in place, e.g.
http {
... ## some stuff, log codecs, and so on.
upstream backend {
server localhost:8001
server localhost:8002
}
server {
hear 80 default_server;
server_name foo.com;
location / {
proxy_pass http://backend/foo/bar/;
}
}
}
However I might prefer to parameterize the proxy_pass
URL with a price/variable that is particular to the chosen upstream server. For instance, if the server with port 8001 is chosen, I might like to make use of proxy_pass http://backend/foo/bar/8001
, and likewise if the server with port 8002 is chosen, I might like to make use of proxy_pass http://backend/foo/bar/8002
(the place backend
is clearly changed by the chosen server identify, as per nginx’s traditional load-balancing setup).
Does anybody know if that is doable?
(I do know I might do some self-routing inside nginx to realize this … e.g. organising two new nginx addresses which might be the upstreams, then proxy_pass
every a kind of individually, however I am questioning if there is a method to dynamically rewrite the URL handed to the upstream server after the subsequent upstream server to strive has been chosen by the load-balancing system.)