- Foreword: I am aware that in the config I am showing below, the domain name was replaced. I did read the warning about this, but as my question is about suggestions in Caddyfile samples, not about a bug in some actual use of Caddy, there are no (for the moment) actual domain names involved.
1. The problem I’m having:
I am using Caddy and layer4 to handle Let’s Encrypt certificate automation and TLS termination then forward cleartext traffic to a local server. The commonly suggested solution is a Caddyfile like this one:
{
layer4 {
:1234 {
@example_com_route tls sni example.com
route @example_com_route {
tls
proxy 127.0.0.1:4567
}
}
}
}
example.com {
respond "OK" 200
}
The last part is the one which causes Caddy to provision the LE certificate. It does so by declaring a “dummy” HTTPS server, which I do not need otherwise.
I would like to have LE automation for the domains mentioned in the layer4 configuration but without the “dummy” HTTPS server.
2. Error messages and/or full log output:
N/A.
3. Caddy version:
# caddy version
v2.10.0 h1:fonubSaQKF1YANl8TXqGcn4IbIRUDdfAkpcsfI/vX5U=
# _
4. How I installed and ran Caddy:
Using Debian 13 (Trixie) on arm64 hardware, I ran the following commands:
# extrepo enable caddyserver
# apt update
# apt install caddy
However this package did not include layer4 support, so I downloaded the (arm64, again) binary from Download Caddy , selecting mholt/caddy-l4 as the only extra feature, and overwrote /usr/bin/caddy with the downloaded binary.
a. System environment:
Debian 13 Trixie up to date, Caddy package from extrepo caddyserver, with /usr/bin/caddy replaced (see above), all running on actual (arm64) hardware.
b. Command:
Caddy is enabled and started by systemd. The only command I use is to reload the configuration:
# /usr/bin/caddy reload --config /etc/caddy/Caddyfile
c. Service/unit/compose file:
Provided by the Debian 13 package
# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
d. My complete Caddy config:
{
layer4 {
:1234 {
@example_com_route tls sni example.com
route @example_com_route {
tls
proxy 127.0.0.1:4567
}
}
}
}
example.com {
respond "OK" 200
}
5. Links to relevant resources:
- Example of a suggestion to declare a “dummy” site on the caddy-l4 github: [solved] Caddyfile syntax for TLS termination and TLS automation · Issue #332 · mholt/caddy-l4 · GitHub
- I have seen (and tried) the solution suggested in Can caddy-l4 do automated TLS renewal? - #2 by Monviech and it too results in a “dummy” HTTPS server.
Thanks for your help!
Albert