Can I use Caddyfile and layer4 together?

I’m using Caddy to serve a couple of sites/services, usually by forwarding them to a docker container. For this I’m using a Caddyfile. I would really like to keep the Caddyfile to configure the sites, in fact one of my main reasons to switch from nginx to Caddy was that adding a site in Caddy is 3 lines while in nginx it’s 30 or so.

But now I would like to use the same* Caddy to terminate SSL (TLS) for an MQTT server. I think this is possible using the layer4 app, but I also think the layer4 app can only be configured using JSON.

Now I’m not sure what would be the best way to plug these together. I could probably hack together a shell script that uses caddy adapt and jq to build a final JSON config, but this comment in a thread about a similar use case somewhat suggests there might be a better, caddy-internal solution?

What would be your advice?

* I could run another Caddy on a port other than 443, but I vaguely remember that it breaks the Let’s encrypt challenges.

caddy-l4 doesn’t have official Caddyfile support. But there is a plugin that can add some primitive support for it via Caddyfile global options:

Otherwise, your only option is to adapt your Caddyfile to JSON, then manipulate it to add your layer4 stuff to it.


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