1. The problem I’m having:
I’m am trying to set up a TCP reverse proxy for MQTT on port 8883 that terminates TLS. Therefore I am using the layer4 app. I would like to use custom generated certificates for that.
The problem I am having is that I have not found a way to configure my own certificates for the TLS server. I would have expected to use a directive tls <cert_file> <key_file>
, but that does not seem to work inside the layer4 block.
How can I configure custom certificates for TLS termination in the layer4 app?
2. Error messages and/or full log output:
3. Caddy version:
I run caddy built with the caddy-l4 and the caddy-docker-proxy inside docker compose.
caddy version
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=
4. How I installed and ran Caddy:
a. System environment:
Inside a docker container, Caddy was built with
xcaddy build \
--with github.com/mholt/caddy-l4 \
--with github.com/lucaslorentz/caddy-docker-proxy/v2
c. Service/unit/compose file:
services:
caddy:
container_name: reverse-proxy
image: my_caddy:1.0
networks:
- app-network
environment:
- CADDY_DOCKER_CADDYFILE_PATH=/etc/caddy/Caddyfile
- CADDY_INGRESS_NETWORKS=app-network
volumes:
- ./tls.crt:/etc/ssl/tls.crt:ro
- ./tls.key:/etc/ssl/tls.key:ro
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data:/data
ports:
- 1883:1883
- 8883:8883
mosquitto:
container_name: mosquitto
image: eclipse-mosquitto:2
networks:
- app-network
volumes:
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf
networks:
app-network:
name: app-network
d. My complete Caddy config:
localhost
{
local_certs
skip_install_trust
layer4 {
:1883 {
route {
proxy mosquitto:1883
}
}
:8883 {
route {
tls
proxy mosquitto:1883
}
}
}
}