1. Caddy version (caddy version
):
v2.3.0
2. How I run Caddy:
I run Caddy with docker, both Caddys.
a. System environment:
Docker
b. Command:
does not apply
c. Service/unit/compose file:
- Caddy, proxy server
services:
caddy:
image: caddy/caddy:alpine
volumes:
- /opt/docker-common/config/caddy/Caddyfile:/etc/caddy/Caddyfile
- /opt/docker-common/config/caddy/shared:/etc/caddy/shared
- /opt/docker-common/data/caddy:/data/caddy
- /opt/docker-common/logs/caddy:/var/log/caddy
ports:
- "XXX.XXX.XXX.XXX:80:80"
- "XXX.XXX.XXX.XXX:443:443"
networks:
- frontend
- backend
restart: always
networks:
frontend:
backend:
- Caddy which serves as the http server
services:
caddy:
image: caddy/caddy:alpine
volumes:
- /opt/docker-hosting/config/caddy/Caddyfile:/etc/caddy/Caddyfile
- /opt/docker-hosting/config/caddy/shared:/etc/caddy/shared
- /opt/docker-hosting/data/caddy:/data/caddy
- /opt/docker-hosting/www:/srv
- /opt/docker-hosting/logs/caddy:/var/log/caddy
expose:
- 80
networks:
- backend
restart: always
networks:
backend:
external:
name: docker-common_backend
d. My complete Caddyfile or JSON config:
- Caddy as a proxy server
portainer.domain.com {
reverse_proxy docker-common_portainer_1:9000
}
:80, :443 {
reverse_proxy docker-hosting_caddy_1:80 {
# I found the below 2 lines in the forum
header_up Host {http.reverse_proxy.upstream.hostport}
header_up X-Forwarded-Host {host}
}
}
- Caddy behind the other Caddy
{
auto_https off
}
anotherdomain.com {
root * /srv/anotherdomain.com
file_server
}
3. The problem I’m having:
I am obivously missing something here so sorry for maybe a duplicate question…
I need to use Cady behind Caddy, proxy from one to another. I am sure I found something in the forum but nothing seems to work reliably.
The idea is to have one Caddy exposed on ports 80 and 443. This first Caddy will run as a proxy server and will take care of ACME requests. I am now testing with portainer and then trying to use “catch-all” to redirect all the rest to the other Caddy instance.
It works okay with portainer, it loads fine but nothing gets forwarded to the other instance of Caddy. I get “ERR_SSL_PROTOCOL_ERROR” and then 502 error.
I assume it has something to do with passing the Host but again, I see no clue in the logs at all.
4. Error messages and/or full log output:
- Caddy, exposed proxy server
caddy_1 | {"level":"error","ts":1615978305.2401366,"logger":"http.log.error","msg":"dial tcp 172.19.0.5:80: connect: connection refused","request":{"remote_addr":"XXX.XXX.XXX.XXX:56062","proto":"HTTP/1.1","method":"GET","host":"domain.com","uri":"/index.html","headers":{"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.186 Safari/537.36"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["cs-CZ,cs;q=0.9,en-US;q=0.8,en;q=0.7"],"If-Modified-Since":["Tue, 16 Mar 2021 23:12:14 GMT"],"Dnt":["1"],"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"],"If-None-Match":["\"qq34ge8\""],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"]}},"duration":0.006175518,"status":502,"err_id":"ut93ajtu1","err_trace":"reverseproxy.statusError (reverseproxy.go:783)"}
- Caddy behind caddy (the request does not even arrive)
caddy_1 | {"level":"info","ts":1615975795.8612862,"logger":"admin","msg":"stopped previous server"}
caddy_1 | {"level":"info","ts":1615975795.8657508,"msg":"shutdown done","signal":"SIGTERM"}
caddy_1 | {"level":"info","ts":1615975798.3833447,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
caddy_1 | {"level":"info","ts":1615975798.3958807,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
caddy_1 | {"level":"info","ts":1615975798.3964393,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc00041c540"}
caddy_1 | {"level":"info","ts":1615975798.397503,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
caddy_1 | {"level":"info","ts":1615975798.3975322,"msg":"serving initial configuration"}
caddy_1 | {"level":"info","ts":1615975798.398879,"logger":"tls","msg":"cleaned up storage units"}
5. What I already tried:
I searched forum, online via search engines and also used my previous experience with proxy in Caddy. I also looked in the docs.
6. Links to relevant resources:
does not apply