Here’s a formatted issue for the Caddy GitHub repository regarding Consul integration:
1. The problem I’m having:
I’m trying to use Caddy as a reverse proxy with Consul service discovery. Specifically, I want to reverse proxy to a service registered in Consul using the service name (web.service.consul). When I try to use the Consul DNS name in my Caddyfile like this:
The proxy doesn’t work. I can confirm that the service is properly registered in Consul and resolvable via dig:
$ dig @localhost -p 8600 web.service.consul
;; ANSWER SECTION:
web.service.consul. 0 IN A X.X.X.138
2. Error messages and/or full log output:
2025/01/01 11:41:55 [ERROR] [nginx.brimble.io] failed to lookup service address: lookup web.service.consul: no such host
2025/01/01 11:41:55 [ERROR] [nginx.brimble.io] reverse proxy upstream could not be resolved: no addresses available
3. Caddy version:
$ caddy version
v2.7.6 h1:xxx
4. How I installed and ran Caddy:
a. System environment:
OS: Ubuntu 22.04 LTS
Architecture: amd64
Consul version: 1.16.6
b. Command:
sudo systemctl start caddy
c. My complete Caddy config:
nginx.brimble.io {
reverse_proxy {
to web.service.consul:3333
}
}
I can resolve the service using dig @localhost -p 8600
I can curl the service directly using its IP:port
I’m looking for guidance on how to properly configure Caddy to work with Consul’s DNS service discovery. If there’s a better approach or a recommended plugin for this use case, I’d appreciate that information as well.
While you can resolve the service name via dig by talking directly to the consul service (port 8600), have you tried to do the same by asking the OS resolver? Caddy is using the default OS resolver.
I don’t follow. Unless your upstream runs Caddy with the default page, then you’re not running the config you think you’re running.
First, I see in some places you’re using web.service.consul while in others using web.service.consul:3333. Which one is it? A/AAAA lookups don’t provide port numbers. For that you’ll need SRV lookups.
Second, your top post shows you’re using @localhost -p 8600 to resolve the address. You can just configure Caddy with resolvers localhost:8600.