How do I use Caddy to redirect to my internal domains with pihole

1. The problem I’m having:

I want to use a url http://pihole.home.box instead of having to type my local ip address out http://192.168.50.14:35783. As I understand the only requirements to accomplish this is pihole and caddy, however I can not get it to work. I would then extend this to all self-hosted apps.

I quickly found this note on using Pi-Hole instead of lighttpd however I am not sure where or how I am supposed to install that (should I install it inside the Caddy docker container? Is that even possible?).

What I want help with:

  1. Sanity check of “Is this setup possible”
  2. Sanity check for given the docker-compose below should the Caddyfile be at /DATA/AppData/caddy/caddyfile/Caddyfile
  3. And then, most importantly Is there some wiki guide I missed on how to achieve the basic setup?
    • Using pi-hole and caddy in two different images to setup the name forwarding.

2. Error messages and/or full log output:

{"level":"info","ts":1707596639.344459,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"info","ts":1707596639.3463495,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"warn","ts":1707596639.3464491,"logger":"http.auto_https","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
{"level":"info","ts":1707596639.3466084,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0004a0200"}
{"level":"info","ts":1707596639.3467095,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"info","ts":1707596639.346872,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1707596639.3469145,"msg":"serving initial configuration"}
{"level":"warn","ts":1707596639.352472,"logger":"tls","msg":"storage cleaning happened too recently; skipping for now","storage":"FileStorage:/data/caddy","instance":"b54d6bf4-4de5-4eec-ac85-3e75b52b3620","try_again":1707683039.3524709,"try_again_in":86399.999999666}
{"level":"info","ts":1707596639.352601,"logger":"tls","msg":"finished cleaning storage units"}

3. Caddy version:

caddy:2.7.6

4. How I installed and ran Caddy:

It was installed with CasaOS. The relevant docker file is from here docker file

a. System environment:

Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-94-generic x86_64)

b. Command:

Docker is starting it with

caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. Service/unit/compose file:

Docker file

docker-compose.yml
name: caddy
services:
  app:
    image: caddy:2.7.6
    restart: unless-stopped
    ports:
      - target: 80
        published: 80
        protocol: tcp
      - target: 443
        published: 443
        protocol: tcp
      - target: 2019
        published: 2019
        protocol: tcp
    volumes:
      - type: bind
        source: /DATA/AppData/$AppID/data
        target: /data
      - type: bind
        source: /DATA/AppData/$AppID/config
        target: /config
      - type: bind
        source: /DATA/AppData/$AppID/caddyfile
        target: /etc/caddy/caddyfile
x-casaos:
  architectures:
    - amd64
    - arm
    - arm64
  main: app
  description:
    en_us: Caddy - The Ultimate Server with Automatic HTTPS.  Need to run tools/install_caddy.sh before installing the template.
  tagline:
    en_us: Caddy - The Ultimate Server With Automatic Https.  Need To Run Tools/install_caddy.sh Before Installing The Template.
  developer: ''
  author: WisdomSky
  icon: https://raw.githubusercontent.com/pi-hosted/pi-hosted/master/images/caddy.png
  thumbnail: https://raw.githubusercontent.com/pi-hosted/pi-hosted/master/images/caddy.png
  title:
    en_us: Caddy
  category: Coolstore
  port_map: '80'

(also given this docker file my Caddyfile should be at /DATA/AppData/caddy/caddyfile/Caddyfile right?)

d. My complete Caddy config:

The setup I tried had this.

{
  auto_https off
  debug
}

pihole.home.box:80 {
  reverse_proxy http://192.168.50.14:35783
}

4. What I tried.

I tried a bunch of things the the thing that seemed most correct.
Added an entry in pi-holes DNS record that points
pihole.home.box192.168.50.14.

Then added the Caddy config above.

When I got to 192.168.50.14 I get the “Caddy works!” page, with the DNS record when navigating to pihole.home.box to it shows me the “Caddy works!” page. However given the config above it should have gone to the pihole port.

The target looks wrong, it needs to be Caddyfile with an uppercase C. Unix filesystems are case sensitive (unlike Windows’ NTFS).

That’s probably why you see the default page, because you’re not actually overwriting the default Caddyfile currently.

You don’t need this if you’re already explicitly using HTTP sites.

I’d write it like this (no practical difference):

http://pihole.home.box {
  reverse_proxy 192.168.50.14:35783
}

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