1. Caddy version (caddy version
):
I’m using a docker image livekit/caddyl4:v2.5
, which is basically Caddyl4 and caddy-yaml
bundled together.
2. How I run Caddy:
In a docker container.
a. System environment:
Running docker with docker-compose v2.2.3 on Ubuntu 20.04.1 LTS.
b. Command:
docker-compose up
c. Service/unit/compose file:
version: "3.9"
services:
caddy:
image: livekit/caddyl4
command: run --config /etc/caddy.yaml --adapter yaml
restart: unless-stopped
network_mode: "host"
volumes:
- ./caddy.yaml:/etc/caddy.yaml
- ./caddy_data:/data
d. My complete Caddyfile or JSON config:
logging:
logs:
default:
level: INFO
storage:
"module": "file_system"
"root": "/data"
apps:
tls:
certificates:
automate:
- livekit.spvw.de
- livekit-turns.spvw.de
layer4:
servers:
main:
listen: [":443"]
routes:
- match:
- tls:
sni:
- "livekit-turns.spvw.de"
handle:
- handler: tls
- handler: proxy
upstreams:
- dial: ["localhost:5349"]
- match:
- tls:
sni:
- "livekit01.spvw.de"
handle:
- handler: tls
connection_policies:
- alpn: ["http/1.1"]
- handler: proxy
upstreams:
- dial: ["localhost:7880"]
3. The problem I’m having:
Basically, I’m trying to achieve the following logic in pseudocode:
listen_on(443)
if (request.sni == "livekit-turns.spvw.de") {
pass_to("localhost:5349")
} else if (request.sni == "livekit.spvw.de") {
if (http.path == "/api") {
add_header("Access-Control-Allow-Origin", "*")
pass_to("localhost:8080")
} else {
pass_to("localhost:7880")
}
}
Currently, with my config, it works as if I had the following logic instead:
listen_on(443)
if (request.sni == "livekit-turns.spvw.de") {
pass_to("localhost:5349")
} else if (request.sni == "livekit.spvw.de") {
pass_to("localhost:7880")
}
4. Error messages and/or full log output:
No errors, I’m just trying to figure out how to achieve the logic that I have in mind.
5. What I already tried:
I’ve read:
- Getting started
- Quick-starts
- Caddy API
- JSON Config Structure
sections from the official documentation.
However, I have not found a way to code the logic in question. I’ve gone to JSON Config Structure
→ apps
→ layer4
→ handle
. The list of modules available for handle
doesn’t include any http
options, so I’m not sure how can I add an additional match
section inside the handle
r that would use the http
module, filter things by the path
and route them to different local services (optionally adding certain CORS headers to it). I’m unsure if the documentation has something missing or if I’m just searching in the wrong place or doing something wrong. Any help would be appreciated
Basically, I want the internal handle
section of the last match
of the livekit01.spvw.de
to correspond to the following nginx code if it makes any sense:
http {
server {
listen 443 ssl http2;
server_name livekit01.spvw.de;
location / {
proxy_pass localhost:7880;
}
location /api {
add_header 'Access-Control-Allow-Origin' '*';
proxy_pass localhost:8080
}
}
}
(I approximately know how to write the given nginx logic for a single host without an SNI, i.e. without the layer4 module that I’m currently using, but I’m not sure how to write this logic in combination with the logic that I’ve had so far that respects the SNI etc)
Sorry, a caddy
newbie here