Order / processing of handle directives unclear

The sorting algorithm for directives is explained here:

abort has a lower order than handle, so it will be sorted below those.

handle blocks are mutually exclusive from eachother, only the first matching one will run. You could put your abort inside a handle which has your matcher.

The tricky bit though is that handle with path matchers will get sorted above those with other kinds of matchers, which means since your @banned matcher has remote_ip it will end up running after some of your other handles.

One thing you could do is override the order of abort to be before handle using the order global option. That’s a valid thing to do for your case to make sure a connection is aborted before any other kind of handling. Or you could wrap your whole thing in a route to make the order things appear in your Caddyfile be the order it runs in, but I tend not to like that because it adds a level of indentation. Or yeah, you could put your abort inside each handle :man_shrugging:

1 Like