Caddy suddenly directs my site to the wrong directive

:joy:

Minor thing, but I recommend using the root directive instead, like this:

root * {env.HOME}/Downloads
file_server browse

This is because the root directive sets it site-wide, so if you need to add another directive that needs to be aware of root, it’ll already be ready for you. The root subdirective within file_server is typically meant for when you want to override the site-wide root for some reason.

You can do this instead:

reverse_proxy /shark h2c://127.0.0.1:2001

Just in case you weren’t aware, /shark will only match exactly /shark and not /shark/foo, because Caddy’s path matching is exact. Add a * to the end of the matcher to make it match other paths too.

Yeah, I see the problem – running caddy adapt on your config shows that the route with mail2.lilf.ir is after the one for :443. This looks like a bug with the Caddyfile adapter where site blocks with multiple sites including a catch-all will be sorted with the “power” of the longest hostname in that site. Fixing that bug might be kinda tricky.

The fix though is to split up your :443 and np.zii.lilf.ir into their own sites such that they each get handled separately. Doing that, the :443 site will get properly sorted to the end.

You can make use of Caddyfile snippets to avoid duplication though, so you can have one snippet with the site contents that you import into both sites:

FYI @matt :point_up: bug with the site sorting :slightly_frowning_face:

2 Likes