1. The problem I’m having:
I’m attempting to use Caddy docker container to access a DNS over HTTPS docker container via reverse_proxy but reverse_proxy does not allow specific path. Therefore I’ve attempted to use rewrite and route both to no avail.
2. Error messages and/or full log output:
Using reverse_proxy (see below Caddyfile), I get the below error:
2023-05-11T22:18:25.903890677Z {"level":"error","ts":1683843505.9037302,"logger":"http.log.error","msg":"dial tcp 192.168.90.15:80: connect: connection refused","request":{"remote_ip":"162.158.90.202","remote_port":"11342","proto":"HTTP/2.0","method":"GET","host":"doh.greghao.com","uri":"/getnsrecord?name=uci.edu&type=A","headers":{"Cdn-Loop":["cloudflare"],"X-Forwarded-For":["152.70.152.203"],"X-Forwarded-Proto":["https"],"User-Agent":["curl/7.81.0"],"Cf-Connecting-Ip":["152.70.152.203"],"Cf-Ipcountry":["US"],"Accept-Encoding":["gzip"],"Cf-Ray":["7c5dcc378a872b63-LAX"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Accept":["*/*"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"doh.greghao.com"}},"duration":0.000406688,"status":502,"err_id":"ecfmh2pa1","err_trace":"reverseproxy.statusError (reverseproxy.go:1299)"}
Using rewrite, I get the below error:
2023-05-11T22:14:00.367304684Z {"level":"error","ts":1683843240.366963,"logger":"http.log.error","msg":"dial tcp 192.168.90.15:443: connect: connection refused","request":{"remote_ip":"162.158.90.202","remote_port":"15852","proto":"HTTP/2.0","method":"GET","host":"doh.greghao.com","uri":"/getnsrecord?name=uci.edu&type=A","headers":{"Cf-Connecting-Ip":["152.70.152.203"],"Cf-Ipcountry":["US"],"Cdn-Loop":["cloudflare"],"X-Forwarded-For":["152.70.152.203"],"Cf-Ray":["7c5dc5bbfcc92b77-LAX"],"X-Forwarded-Proto":["https"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"User-Agent":["curl/7.81.0"],"Accept-Encoding":["gzip"],"Accept":["*/*"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"doh.greghao.com"}},"duration":0.000367245,"status":502,"err_id":"z24k4gg5g","err_trace":"reverseproxy.statusError (reverseproxy.go:1299)"}
Using route, I get the below error:
2023-05-11T22:15:54.154310804Z {"level":"error","ts":1683843354.1540062,"logger":"http.log.error","msg":"dial 192.168.90.15: unknown network 192.168.90.15","request":{"remote_ip":"172.70.207.10","remote_port":"43808","proto":"HTTP/2.0","method":"GET","host":"doh.greghao.com","uri":"/getnsrecord?name=uci.edu&type=A","headers":{"Cf-Ray":["7c5dc8831c1808f2-LAX"],"Cf-Connecting-Ip":["152.70.152.203"],"X-Forwarded-For":["152.70.152.203"],"X-Forwarded-Proto":["https"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"User-Agent":["curl/7.81.0"],"Accept":["*/*"],"Cf-Ipcountry":["US"],"Cdn-Loop":["cloudflare"],"Accept-Encoding":["gzip"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"doh.greghao.com"}},"duration":0.000172135,"status":502,"err_id":"74u4cy0xv","err_trace":"reverseproxy.statusError (reverseproxy.go:1299)"}
Using handle_path, I get the below error:
2023-05-11T22:24:57.375965596Z {"level":"error","ts":1683843897.375762,"logger":"http.log.error","msg":"dial 192.168.90.15: unknown network 192.168.90.15","request":{"remote_ip":"172.69.34.76","remote_port":"44032","proto":"HTTP/2.0","method":"GET","host":"doh.greghao.com","uri":"/getnsrecord?name=uci.edu&type=A","headers":{"X-Forwarded-Proto":["https"],"User-Agent":["curl/7.81.0"],"Accept":["*/*"],"Cf-Ipcountry":["US"],"Cdn-Loop":["cloudflare"],"Accept-Encoding":["gzip"],"Cf-Connecting-Ip":["152.70.152.203"],"X-Forwarded-For":["152.70.152.203"],"Cf-Ray":["7c5dd5c63faf520e-LAX"],"Cf-Visitor":["{\"scheme\":\"https\"}"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"doh.greghao.com"}},"duration":0.000198686,"status":502,"err_id":"wku7aryza","err_trace":"reverseproxy.statusError (reverseproxy.go:1299)"}
3. Caddy version:
v2.6.4
4. How I installed and ran Caddy:
Pulled from docker hub
a. System environment:
Ubuntu Linux/Docker
b. Command:
docker-compose -f ~/docker/docker_compose.yml up -d
c. Service/unit/compose file:
version: '3.7'
networks:
caddy:
external: true
name: caddy
default:
driver: bridge
services:
caddy:
container_name: caddy
image: caddy:latest
restart: unless-stopped
networks:
caddy:
ipv4_address: 192.168.90.254
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- $APPDIR/Caddyfile:/etc/caddy/Caddyfile
- $APPDIR/caddy_data:/data
- $APPDIR/caddy_config:/config
doh-server:
image: satishweb/doh-server
container_name: doh
restart: always
networks:
caddy:
ipv4_address: 192.168.90.15
environment:
DEBUG: "0"
DOH_HTTP_PREFIX: "/getnsrecord"
DOH_SERVER_LISTEN: ":8053"
DOH_SERVER_TIMEOUT: "10"
DOH_SERVER_TRIES: "3"
DOH_SERVER_VERBOSE: "true"
d. My complete Caddy config:
#doh.greghao.com {
# route /getnsrecord {
# reverse_proxy 192.168.90.15/getnsrecord
# }
#}
#doh.greghao.com {
# reverse_proxy /getnsrecord 192.168.90.15
#}
#doh.greghao.com {
# rewrite * /getnsrecord{uri}
# reverse_proxy https://192.168.90.15
#}
doh.greghao.com {
handle_path /getnsrecord {
reverse_proxy 192.168.90.15/getnsrecord
}
}