Organizing Sites into multiple Caddyfiles

Hi @acole, welcome to the Caddy community.

Caddy doesn’t have the site enable / disable aliases Apache does that moves/removes symlinks automatically, but Caddy can import multiple files when starting up, just like Apache does.

You can use one central Caddyfile with import directives, e.g.

import /path/to/site1/Caddyfile
import /path/to/site2/Caddyfile
# ... rinse and repeat

Or just one import directive that fetches a glob:

import /path/to/*.caddy

Then populate the /path/to/ directory with files that end in .caddy.

The -conf flag also accepts a glob directly, e.g. -conf '/path/to/*.caddy'. This functions exactly the same way import /path/to/*.caddy does, removing the requirement for a single central Caddyfile with one import directive in it.

You don’t need to use *.caddy - you could just use /path/to/caddyfiles/* and import every single file in the folder. I use the .caddy extension so I can “disable” sites in the folder by removing the extension and “re-enable” them by adding it back.

5 Likes