Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverseproxy: allow upstream to have a name or route #6125

Open
ottenhoff opened this issue Feb 24, 2024 · 4 comments
Open

reverseproxy: allow upstream to have a name or route #6125

ottenhoff opened this issue Feb 24, 2024 · 4 comments
Labels
discussion 💬 The right solution needs to be found

Comments

@ottenhoff
Copy link
Contributor

Currently, a reverse proxy config looks like this:

reverse_proxy 
  to https://server101.local:8443 https://server102.local:8443
}

It would be nice if the upstreams had a name like server101 and server102. A few reasons:

a) Land on a specific upstream by adding GET param lb=server101
b) Land on a specific upstream by setting header lb: server101
c) Land on a specific upstream by parsing cookie, e.g., JSESSIONID=uuid.server101

Here is a sample config from another load-balancer that shows the idea:

upstream backend {
    server backend1.example.com route=a;
    server backend2.example.com route=b;
    sticky route $route_cookie $route_uri;
}
@francislavoie
Copy link
Member

Prior art: #4350

@ottenhoff ottenhoff changed the title reverseproxy: allow upstream to have a name reverseproxy: allow upstream to have a name or route Feb 25, 2024
@mholt
Copy link
Member

mholt commented Mar 6, 2024

I would suggest using a map directive in conjunction with a placeholder for the upstream address; that way you can map an arbitrary string to a backend address, then use that. 👍

And if you need to load balance to two backends you can map to multiple placeholders and then specify both in the reverse proxy config.

@mholt mholt added the discussion 💬 The right solution needs to be found label Mar 6, 2024
@ottenhoff
Copy link
Contributor Author

Ultimately, the goal here for me is to support a new lb_policy that routes based on the application's cookie instead of Caddy's inserted cookie.

Tomcat is a popular Java application server and often sends cookies like JSESSIONID=xxxxx-yyyyy-zzzzzzz.appserver1094. It would be easier to write a new lb_policy if there was a name for each upstream. I suppose I could just check for the presence of a map in a custom lb_policy, but it seemed like a common enough use case supported by other loadbalancers that I should write it up.

@mholt
Copy link
Member

mholt commented Apr 11, 2024

Can you just use the map directive with the {cookie.JSESSIONID} placeholder? Then you could set an upstream that way. I guess it's not clear to me why that isn't a sufficient solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion 💬 The right solution needs to be found
Projects
None yet
Development

No branches or pull requests

3 participants