How to use multiple overlapping named matchers?

I have a reverse proxy setup where a bare https://example.com is protected by Authelia, and https://example.com/whatever_here is not. The idea is to limit the people who can create a shared file (the GUI is at https://example.com), but freely allow for the files to be retrieved by anyone when they know the URI ( https://example.com/some_key_here):

https://example.com {
	@add_file {
		path /
	}
	@share_file {
		path /*
	}
	reverse_proxy @share psitransfer:3000
	import authenticate-with-authelia
	reverse_proxy @share_file psitransfer:3000
}

The idea is to first match the freely available URI, and then if there is no match, load the Authelia configuration, and then allow for the GUI in case the authentication is OK.

Now I would like to extend this configuration by having https://example.com/admin protected by Authelia, via a new named matcher:

	@admin {
		path /admin
	}

My problem: I do not know how to mix this with the setup above. Either

  • I match @admin first (but I would need to import authenticate-with-authelia and have everything authenticated (including what I do not want) → :frowning:
  • or I first match @share_file and it will also match /admin:frowning:

Ideally, I would look for conditional blocks such as

if @admin then { import authenticate-with-authelia; reverse_proxy ...} 

but it looks like the matcher always comes after the command (or rather, in addition to the command).

How can I approach this?

Pretty sure you’re looking for handle.

I’m not entirely sure I follow what you’re trying to do in particular, but that’s how you separate routing into mutually exclusive routes.

Next time, please fill out the help topic template, as per the forum rules. You also didn’t give you entire Caddyfile, so it’s difficult to know exactly what to suggest. It’s important that you give full details so we’re on the same page.

1 Like

Yes, I was looking for handle. Thank you!

Yes, sorry for that. The Caddyfile I provided is actually the complete one - what was indeed missing is the content of the import. Point taken.