Caddy deployed with docker compose, listening on ports 80 and 443, my application is deployed on port 8877, through domain.com reverse proxy to port 8877, domain access is normal and ip:port is also accessible, but now I want to allow only the domain access but not the ip port access, can I achieve this through caddy configuration?
2. Error messages and/or full log output:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
2.9.1
3. Caddy version:
4. How I installed and ran Caddy:
a. System environment:
b. Command:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
c. Service/unit/compose file:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
d. My complete Caddy config:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
Caddy can’t do that for you. However, you can modify your Docker Compose setup by replacing this:
ports:
- '3004:443'
with, for example, this:
ports:
- '127.0.0.1:3004:443'
If your Caddy container is deployed with network_mode: host, you can use:
reverse_proxy 127.0.0.1:3004
If your Caddy container is running in bridge mode under the same bridge as easyimage, you don’t need to expose the easyimage port via ports. Instead, you can use:
If caddy is using bridge mode, the web application (port 8833) is not deployed using docker, and the firewall closes port 8833, is caddy not able to proxy the application?
It looks like you’re running Caddy in bridge mode. So this:
domain.com {
reverse_proxy 127.0.0.1:8883
}
will make Caddy proxy to itself inside the container.
To achieve what you want, add this to your Caddy Docker Compose file:
network_mode: host
and remove ports section.
Edit:
I should have mentioned that network_mode: host works only on Linux. So if you’re running your Caddy container on a different OS, or you simply don’t want to change the network mode, update your Caddyfile configuration from this:
I used the method you described above. Errors reported in caddy logs after domain access
{"level":"error","ts":1742630104.1104808,"logger":"http.log.error","msg":"dial tcp: lookup host.docker.internal on 127.0.0.11:53: no such host","request":
So given your new compose.yaml configuration, I presume you’re running on Windows? I don’t believe the extra_hosts should be necessary, since Docker automatically handles the DNS for the host machine’s IP from host.docker.internal. Leave the reverse_proxy on host.docker.internal, but remove the extra_hosts from your compose.yaml.