Can I tell Caddy which IP/interface to use to serve the website?

1. The problem I’m having:

It’s not as much a problem I’m having, more a question. I have two ethernet card on my Raspberry Pi. One will be used for serving internet (Pi-Hole and Caddy) and the other interface for internal network with a VLAN enabled network switch.

I’m serving a simple static website using Caddy. Later on I want to serve some more sites and do reverse proxies. Right now I’m wondering if it’s possible to tell Caddy to serve that website using x ip or eth0 or eth1?

This is probably done in the DNS server?

2. Error messages and/or full log output:

ger":"tls.cache.maintenance","msg":"attempting certificate renewal","identifiers":["192.168.102.25"],"remaining":14155.356319068}
Jan 04 18:00:02 pi-hole caddy[905]: {"level":"info","ts":1704387602.64424,"logger":"tls.renew","msg":"acquiring lock","identifier":"192.168.102.25"}
Jan 04 18:00:02 pi-hole caddy[905]: {"level":"info","ts":1704387602.6517503,"logger":"tls.renew","msg":"lock acquired","identifier":"192.168.102.25"}
Jan 04 18:00:02 pi-hole caddy[905]: {"level":"info","ts":1704387602.6523647,"logger":"tls.renew","msg":"renewing certificate","identifier":"192.168.102.25","remaining":14155.347640215}
Jan 04 18:00:02 pi-hole caddy[905]: {"level":"info","ts":1704387602.6632953,"logger":"tls.renew","msg":"certificate renewed successfully","identifier":"192.168.102.25"}
Jan 04 18:00:02 pi-hole caddy[905]: {"level":"info","ts":1704387602.6636083,"logger":"tls.renew","msg":"releasing lock","identifier":"192.168.102.25"}
Jan 04 18:00:02 pi-hole caddy[905]: {"level":"info","ts":1704387602.6637964,"logger":"tls","msg":"reloading managed certificate","identifiers":["192.168.102.25"]}
Jan 04 18:00:02 pi-hole caddy[905]: {"level":"warn","ts":1704387602.6645358,"logger":"tls","msg":"stapling OCSP","error":"no OCSP stapling for [192.168.102.25]: no OCSP server specified in certificate","identifiers":["192.168.102.25"]}
Jan 04 18:00:02 pi-hole caddy[905]: {"level":"info","ts":1704387602.6645977,"logger":"tls.cache","msg":"replaced certificate in cache","subjects":["192.168.102.25"],"new_expiration":1704430803}

3. Caddy version:

v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

Installed Caddy using apt-get. After that I downloaded the latest version of of Github and replaced the binary file.

a. System environment:

Debian 12 Bookworm
systemd 252 (252.19-1~deb12u1)

I start Caddy using systemd.

b. Command:

sudo systemctl start (or restart) caddy

c. Service/unit/compose file:

d. My complete Caddy config:

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

site.dev, www.site.dev {
        root * /var/www/site.dev/public_html
        file_server
        encode zstd gzip
}

192.168.102.25 {
        encode zstd gzip
        redir / /admin{uri}
        reverse_proxy 127.0.0.1:1080
}

5. Links to relevant resources:

Use the bind directive within a site to specify the interface:

Oh that’s brilliant. Thank you so much, I’m loving Caddy more and more :sweat_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.