Caddyfile and v2

Ah… duh, this is because the adapted JSON contains:

"routes": [
	{
		"handle": [
			{
				"handler": "vars",
				"root": "/var/www/talks/"
			}
		],
		"match": [
			{
				"path": [
					"/talks/*"
				]
			}
		]
	},
	{
		"handle": [
			{
				"handler": "vars",
				"root": "/var/www/home"
			}
		]
	},
	...

which is normally what you’d want (the more specific handler goes first) but in this case, they need to be mutually exclusive. The second overwrites the first.

One way to solve this would be to structure your Caddyfile more like nginx config’s location blocks:

gon.cat

handle /talks/* {
    strip_prefix /talks/
    root /var/www/talks
}
handle {
    root /var/www/home
}
file_server

Another way would be for us/me to make the root directive mutually exclusive from all other root directive (kind of like handle and rewrite are).

Another way would be to define a matcher that makes them mutually exclusive yourself (i.e. “not /talks/” instead of catch-all).

Another way would be to define multiple sites:

gon.cat {
    root /var/www/home
    file_server
}

gon.cat/talks/* {
    root /var/www/talks
    strip_prefix /talks/
    file_server
}
1 Like