Web / Caddy Server Interview questions
What is the purpose of the layer4 app in Caddy?
Caddy's core HTTP app operates at layer 7 - it understands hostnames, paths, and headers. The layer4 app (also called caddy-l4, maintained as a separate module) extends Caddy down to layer 4, letting it route raw TCP and UDP connections before any protocol-specific parsing happens.
{ "apps": { "layer4": { "servers": { "mux": { "listen": [":443"], "routes": [ { "match": [{ "tls": { "sni": ["ssh.example.com"] } }], "handle": [{ "handler": "proxy", "upstreams": [{"dial": ["10.0.0.5:22"]}] }] }, { "match": [{ "http": [] }], "handle": [{ "handler": "proxy", "upstreams": [{"dial": ["localhost:8443"]}] }] } ] } } } } }
This is used for scenarios plain HTTP routing can't handle - for example, sharing a single port 443 between HTTPS traffic and an SSH or database connection that also happens to arrive over TLS, by inspecting the TLS ClientHello's SNI field before deciding where to send the raw bytes. Because it's a separate module, it requires an xcaddy build and, at least in its earlier releases, configuration was JSON-only with no Caddyfile support.
More Related questions...