I recently installed Caddy on one of my edge servers that previously worked as a reverse proxy for multiple websites using nginx. I managed to convert all the nginx templates (one for each site) in Caddyfile format (one .caddy file for each website) and imported all these files with a single centrale Caddyfile with a simple import directive (import *.caddy).
Problem is, any time I change one of the configuration files, I need to perform a /reload of the Caddy configuration, so it takes some time in order to adapt all configs to JSON format and load them. This takes relatively high amount of time and CPU usage.
Is there any way to instruct Caddy to just load one Caddyfile, then “append” another Caddyfile to the existing configuration and so on… so that whenever I need to modify a server (i.e., only ONE of the many Caddyfiles) I can just replace that specific config instead of all of them every time?
The real issue here is that I need to use Caddyfiles and can’t switch to JSON. At least not directly.
From the docs it seems that @id directive is missing for Caddyfile… Also, in my case one Caddyfile contains multiple snippets, server blocks and custom SSL certificates. I need some way to identify the full file with all blocks and snippets.
What I was thinking was to write a code that asks Caddy to adapt each Caddyfile to JSON format and put an @id for the whole JSON string. I don’t know if this is possible tho, from documentation it seems lile you can assign an ID only to some blocks, but I need one ID for one Caddyfile / JSON, is it feasible?
Adapting configs is very fast. I’m not sure what problem you’re encountering here. Please elaborate. Adapting config and reloading should be near-instant.
No. Caddy has one config (and it’s JSON under the hood). Any change to the config reloads the the entire config (which is fast and light-weight). See Architecture — Caddy Documentation
I have more or less 50 Caddyfiles, esche one containing unique snippets and server blocks (they are quite complicated) automatically generated from user settings.
In my Ubuntu 20.04 VM, with 4vCPU and 4 GB of RAM, when I reload the config all cpus go to 90% usage and it takes at least 30/45 seconds to complete the operation.
The configs have all the same structure, basically it is a template in which values are replaced for each website. One Caddyfile is composed by more or less 600 rows.
They are divided in this way:
First section → snippets → 400 rows of snippets, with 16 snippet blocks
Second section → server blocks (remaining 200 rows) that include the previously defined snippets
I’m using Caddy as a reverse proxy. Auto SSL is disabled (each website has its own custom cert managed elsewhere).