1. Caddy version (caddy version
):
Dockerfile (for Proxy and Webserver):
FROM caddy:2.2.1-builder-alpine AS builder
RUN xcaddy build \
--with github.com/ueffel/caddy-brotli
FROM caddy:2.2.1
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
2. How I run Caddy:
target layout:
Internet --https--> Router with destination NAT --https--> Dockerhost --https--> Caddy Proxy --https--> Caddy Webservers
functional layout:
```Internet --https–> Router with destination NAT --https–> Dockerhost --https–> Caddy Proxy --http–> Caddy Webservers``
For Let’s Encrypt I use the HTTP Challenge at the moment. Planned is do use DNS Challenge with CloudNS, as soon as it is available for Caddy v2.
a. System environment:
OS: OpenSUSE Leap 15.2
Docker: 19.03.11
b. Command:
docker-compose up -d
c. Service/unit/compose file:
Docker-Compose Files:
Loadbalancer/Proxy:
version: "3.7"
services:
caddy:
build: ./caddy
restart: unless-stopped
networks:
medinastation_proxy:
ports:
- "80:80"
- "443:443"
- "443:443/udp"
environment:
- TZ=Europe/Zurich
volumes:
- /home/ei8ht/ch.starterpage/medinastation/caddy/Caddyfile:/etc/caddy/Caddyfile
- /home/ei8ht/ch.starterpage/medinastation/caddy/site:/srv
- /home/ei8ht/ch.starterpage/medinastation/caddy/data:/data
- /home/ei8ht/ch.starterpage/medinastation/caddy/config:/config
- /home/ei8ht/ch.starterpage/medinastation/caddy/log:/var/log
networks:
medinastation_proxy:
external: true
Webserver:
version: "3.7"
services:
nifaweb:
build: ./caddy
container_name: nifaweb
restart: unless-stopped
environment:
- TZ=Europe/Zurich
volumes:
- /home/ei8ht/ch.einmalmitprofis/nightfall/www/caddy/Caddyfile:/etc/caddy/Caddyfile
- /home/ei8ht/ch.starterpage/medinastation/caddy/data:/data
- /home/ei8ht/ch.einmalmitprofis/nightfall/www/caddy/config:/config
- /home/ei8ht/ch.einmalmitprofis/nightfall/www/caddy/log/:/var/log
networks:
medinastation_proxy:
ipv6_address: 2001:1620:58a:cafe::3333
nifawebback:
networks:
medinastation_proxy:
external: true
nifawebback:
d. My complete Caddyfile or JSON config:
Caddyfile Loadbalancer/Proxy:
{
experimental_http3
#acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
email mymail@redacted.me
}
dev.nightfall.einmalmitprofis.ch {
encode br gzip
reverse_proxy https://nifaweb
log {
output file /var/log/nifa.log {
roll_size 1gb
roll_keep 5
roll_keep_for 720h
}
}
}
Caddyfile Webserver:
{
experimental_http3
# acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
email mymail@redacted.me
}
dev.nightfall.einmalmitprofis.ch {
encode br gzip
respond "Hello World on nifaweb"
log {
output file /var/log/nifa.log
}
3. The problem I’m having:
As long as i set the reverse proxy to http://nifaweb and start the webserver in http only, everything works as expected. At the moment I activate https in the “backend”, I get an http error 502. It doesn’t matter if I try to connect with http2 or http3.
4. Error messages and/or full log output:
http2 error:
{"level":"error","ts":1605811536.2540739,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.10.1.151:49152","proto":"HTTP/2.0","method":"GET","host":"dev.nightfall.einmalmitprofis.ch","uri":"/","headers":{"Sec-Fetch-Site":["none"],"Sec-Fetch-Dest":["document"],"Accept-Language":["de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"],"Cache-Control":["max-age=0"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"dev.nightfall.einmalmitprofis.ch"}},"common_log":"10.10.1.151 - - [19/Nov/2020:18:45:36 +0000] \"GET / HTTP/2.0\" 502 0","duration":0.301805448,"size":0,"status":502,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3-29=\":443\"; ma=2592000"]}}
http3:
{"level":"error","ts":1605811555.4709983,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_addr":"10.10.1.151:48045","proto":"HTTP/3","method":"GET","host":"dev.nightfall.einmalmitprofis.ch","uri":"/","headers":{"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"],"Accept-Language":["de,en-US;q=0.7,en;q=0.3"],"Accept-Encoding":["gzip, deflate, br"],"Dnt":["1"],"Alt-Used":["dev.nightfall.einmalmitprofis.ch"]},"tls":{"resumed":false,"version":0,"cipher_suite":0,"proto":"","proto_mutual":false,"server_name":""}},"common_log":"10.10.1.151 - - [19/Nov/2020:18:45:55 +0000] \"GET / HTTP/3\" 502 0","duration":0.302131777,"size":0,"status":502,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3-29=\":443\"; ma=2592000"]}
http2 from remote (Mobile):
{"level":"error","ts":1605811847.390072,"logger":"http.log.error.log1","msg":"remote error: tls: internal error","request":{"remote_addr":"178.197.229.8:61253","proto":"HTTP/2.0","method":"GET","host":"dev.nightfall.einmalmitprofis.ch","uri":"/","headers":{"User-Agent":["Mozilla/5.0 (Android 9; Mobile; rv:82.0) Gecko/82.0 Firefox/82.0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"],"Accept-Language":["de-DE"],"Accept-Encoding":["gzip, deflate, br"],"Dnt":["1"],"Upgrade-Insecure-Requests":["1"],"Te":["trailers"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"dev.nightfall.einmalmitprofis.ch"}},"duration":0.30183744,"status":502,"err_id":"24dmkste1","err_trace":"reverseproxy.(*Handler).ServeHTTP (reverseproxy.go:441)"}
Curl from the Dockerhost (set dev.nightfall.einmalmitprofis.ch in the hostfile to 127.0.0.1):
ei8ht@tycho:~/ch.starterpage/medinastation> curl -IL --http2 https://dev.nightfall.einmalmitprofis.ch
HTTP/2 502
alt-svc: h3-29=":443"; ma=2592000
server: Caddy
date: Thu, 19 Nov 2020 19:11:59 GMT
5. What I already tried:
As I’m a newbie to Caddy I don’t have much experience. Also I’m not to familiar with proxies when it comes to layer 7 protocols. I read the documentation several times, serached on the net. Most Infos I find about this is for Caddy v1. I’m sure to just miss one thing for https/tls connections to the backend but I can’t find it.