Proxy pathmatching quirks

I have been configuring caddy as a load balance proxy for certain pages and noticed something strange that isn’t matching what the documentation says. Wanted to check here if my config is wrong. My proxy section looks like this:

proxy / 127.0.0.1:30111 {
  transparent
except /test/1/direct /test/apps/app/ 
}

proxy /test/apps/app/ 127.0.0.1:30112 127.0.0.1:30113 127.0.0.1:30114 {
  transparent
}
proxy /test/1/direct 127.0.0.1:30113 {
  transparent
}

This issue I am seeing is that the url /test/apps/appnew somehow gets picked up in the except and I get a 404 error.

According to the docs the final ‘/’ in ‘/test/apps/app/’ should stop it from path matching further. I am able to get around this by adding another proxy rule which specifies ‘/test/apps/appnew’ explicitly, but I feel like something is wrong or missing from my config to get it to work as expected.

This issue has to do with the use of path cleaning. The standard Go function is used to sanitise input from the Caddyfile, which strips the trailing slash.

I actually authored a pull request to address this issue with respect to except: #2151 (see also issue #2107 and the original forum discussion).

I don’t think the docs specifically mention that a trailing / will work for except currently - if it does, it should probably be changed until the PR is merged. Can you quote the part of the docs that says that?

Lastly, have you tried without except? The proxy directive should favour the longest matching base path anyway, so you shouldn’t be required to exclude them from the catch-all proxy, as far as I know.

1 Like

Ah I may have read the wrong section thinking it applied to excepts: https://caddyserver.com/docs/http-caddyfile (the Path Matching section).

I had done a cursory search of the github, but must have missed that PR.

Good to know that it’s at least expected for now. I’ll see if I can nudge it toward the behavior I want, I was being a little extra explicit with the excepts. Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.