Organizing Sites into multiple Caddyfiles

I would like to be able to organize my sites into individual caddyfiles. In apache you can store your sites in individual .conf files and enable and disable them with symlinks. As my use of caddy grows so does my caddyfile. I currently organize within the file by using comments but it is starting to get long. Also I worry about coworkers messing up another site when they are editing theirs. Is there currently a way of handling this or is there possibly already a feature request.

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.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.