In caddy(+cloudflare) how to do proxy pass to multiple containers

1. The problem I’m having:

I am new to caddy(with cloudflare support) and doing proxy pass. I have pihole + wireguard-ui + caddy running in one of these cheap vps’s. I am successfully able to run caddy to get a cert from Let’s Encrypt and I am able to access pihole in my url https://vpn.myfancydomain.com/admin/index.php

I would like to introduce wireguard-ui into this mix and have it accessible with the url
https://vpn.myfancydomain.com/wireguard

in addition to pihole now available as

https://vpn.myfancydomain.com/pihole/admin/index.php

I have looked around, considering this is some pretty tame stuff, but I am not hitting the right search terms to get this working. I see a number of results that gives me help on myapp.foo.com and myapp2.foo.com in the same host etc, but I just want different end points rather than different fqdns. Any pointers will be greatly appreciated.

The wireguard-ui container is running on 10.0.0.5 with a container name “wireguard-ui”

2. Error messages and/or full log output:

No error messages

3. Caddy version:

2.8.4

a. System environment:

docker

b. Command:

c. Service/unit/compose file:

services:
  caddy:
    build:
      context: .
      dockerfile: $DOCKERDIR/appdata/caddy/caddy.Dockerfile
    container_name: caddy
    hostname: caddy
    environment:
      - DOCKER_DEFAULT_PLATFORM=$DOCKER_DEFAULT_PLATFORM
    networks:
      net: {}
    restart: unless-stopped
    ports:
      - "80:80" # For HTTP -> HTTPS redirects
      - "443:443"
    dns:
      - 1.0.0.3
    volumes:
      - $DOCKERDIR/appdata/caddy/config/Caddyfile:/etc/caddy/Caddyfile
      - $DOCKERDIR/appdata/caddy/data:/data
      - $DOCKERDIR/appdata/caddy/config:/config
    env_file:
      - /home/ubuntu/.cloudflare_token
    healthcheck:
      test: ["CMD", "caddy", "version"]
    depends_on:
      - pihole
      - cloudflared

d. My complete Caddy config:

vpn.myfancydomain.com {
        reverse_proxy 10.0.0.3:80
        tls myself@mail.com {
                dns cloudflare {env.CLOUDFLARE_API_TOKEN}
        }
}

5. Links to relevant resources:

Use request matchers to split traffic. Read the docs.

But please read this article:

You’re better off using a subdomain per service instead.

1 Like

Thank you very much for that. I will read that up shortly. I don’t mind spinning up separate sub domains per service, with that said, can you point me to some docs that tells me how can I do the letsencrypt cert signing for each of the sub domains that I am spinning up.

You just make a site block per subdomain. That’s it. Caddy handles the rest. See Caddyfile Concepts — Caddy Documentation

1 Like

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