Mixing Caddyfile and JSON mixing

I am running a Caddy instance that in v1 service 6 vhosts.

I am in the process of migrating to v2, but I am running into some serious issues. Some abilities (default logging) can only be manipulated by JSON, but some servers (like Nextstep) are fairly complicated even as Caddyfile. And Just having a top level Caddyfile that imports a directory of vhosts file is A LOT easier than trying to mix everything into a single JSON. Is there any mechanism in Caddy that can import/merge multiple JSON configs? Or can you load a mix of Caddyfile and JSON into a server?

Hey @lexpierce,

Best I can think of is to use caddy adapt to write your config from Caddyfile and then combine the JSON result with your JSON-only tweaks (like default logging).

Yeah. That’s what I’ve been doing. And it’s been a learning experience. I may just run with caddyfile launching, and slam a logging JSON update into the system… do JSON load through the API merge or overwrite?

Per docs: API — Caddy Documentation

You can hit the config path with a POST to set or replace an object; PUT to create a new object; or PATCH to replace an existing object.

Logging is pretty powerful in v2, so it takes a lot of work to expose it in the Caddyfile. It’ll probably happen eventually, but not right away.

My usual v2 logging advice applies: just log slightly more than you need, then filter out lines you don’t want. Since it’s structured, this is very flexible and can be automated with any number of tools.

Well, for some workflows. Remember that over the course of 6 years we’ve seen a lot of use cases.

Not at the moment, but there is some talk of a module that can generate a config from multiple sources: Caddy v2? · Issue #130 · lucaslorentz/caddy-docker-proxy · GitHub

The point is, a single JSON doc sounds inconvenient but then you realize you can layer any other tooling or logic on top of it, and suddenly it becomes the most versatile format ever. Especially when you consider that this logic can be embedded into Caddy either as a config adapter or some other module, so it’s not like you have to hack together a bunch of external tools to make it work. Caddy is capable of doing what you want in the way you want, but somebody has to spec it out and write some code, at some point.

Since the Caddyfile just becomes JSON and then fed into the same API endpoints that @Whitestrake linked to, yes. But note that you can’t go from JSON to Caddyfile; it’s a one-way street.

1 Like

I am 100% ok with that one way street. I just obsess. I am going to get nextcloud ‘working’ and obsess over routes and rewriting rules for awhile at some point here. A lof of rewrites are dropped to make it work with v2 in the Caddyfile.

1 Like

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