-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Overwrite remote_ip with x-forwarded-for for ip_hash load-balancing #5469
Comments
Currently With all the work we've done recently with Coincidentally, I just opened a PR a few hours ago to add another new lb policy. I'll probably add it to this PR in the coming days. #5468 |
Alright, updated #5468 with the new |
Wow, thx! I'll test it right away 🥳 |
just in case you need a working Dockerfile (based on nonroot-image): |
Almost there ... It seems the version prior to 2.7.0 can't choose which header to use for But I can change it in the code for testing and use edit:
Mmmhmm, these are arrays 🤔 I'm trying this now: // Select returns an available host, if any.
func (ClientIPHashSelection) Select(pool UpstreamPool, req *http.Request, _ http.ResponseWriter) *Upstream {
var address string
addresses := caddyhttp.GetVar(req.Context(), "Cf-Connecting-Ip")
switch x := addresses.(type) {
case []string:
address = strings.Join(x, ",")
case string:
address = x
}
clientIP, _, err := net.SplitHostPort(address)
if err != nil {
clientIP = address // no port
}
return hostByHashing(pool, clientIP)
} |
That's not the right way to use it. You're meant to configure both |
Hmm, this was the first I tried because I read it in some other PR (the one saying that the options change with 2.7.0) as comment. But:
This is the commit I'm building:
And this the Global-Section of my Caddyfile:
|
Those go within |
Oh, ok sorry 🙈 I can confirm that it works 👍 Thx a lot 🙌 |
My caddy version is
|
You're probably looking for But also neither of those are in any released version yet. Check the dates on the issues/PRs you're referencing vs the release date of the version you're using. You can build from the |
Yeah i cam from #5104. So in there in order to work do i need to build it from master? Can't i use xcaddy?
|
Yes, but |
Hi,
I've been researching for a couple of hours and still didn't find out if Caddy supports this or not.
My Caddy is behind another Reverse-Proxy (because it can't do
ip_hash
load-balancing 😩 ) but I can't simply swap it because it would require a lot of work that is not doable in a short timeframe.I tried Nginx before but it doesn't support active health checks (except if paying for Plus).
After researching a lot I found out that Caddy is lightweight, has an appealing config file format and supports ip_hash.
Now I'm struggeling with the last problem - maybe a show-stopper, idk - that the load-balancer should use the IP from X-Forwarded-For as remote-ip before it is hashed.
I tried to set the X-Real-IP header to the X-Forwarded-For IP but it doesm't seem to work.
Somewhere else I found that the Log always shows the incoming headers, therefore always shows the IP of my other proxy, but according to the log, it's always the same upstream server that is selected. Therefore I assume that it's not working.
Any ideas if Caddy can do this?
Thx in advance!
The text was updated successfully, but these errors were encountered: