1. The problem I’m having:
I am currently running a caddy instance as my webserver, behind another caddy instance that acts as a reverse proxy (see my previous post). I’d like to add another static site to this and use the reverse proxy to route to the different sites. I was wondering if I could host both sites on the same port and use the caddy webserver to route to the correct one, depending on which domain got routed to the webserver or if I need to host each site on a different port.
3. Caddy version:
I’m using caddy 2.10.2 within docker
4. How I installed and ran Caddy:
a. System environment:
I’m running caddy in docker compose, using the recommended docker compose config.
b. Command:
I’m running through docker without extra commands
c. Service/unit/compose file:
services:
caddy:
image: caddy:2.10.0
restart: unless-stopped
ports:
- 80:80
- 443:443
- 443:443/udp
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./caddy/data:/data
- ./caddy/config:/config
- ./docs/site:/var/www/mysite1
- ./notes/site:/var/www/mysite2
d. My complete Caddy config:
If I need to host every site on a different port, I’d assume my caddy file would look like this:
192.168.5.164:80 {
root * /var/www/mysite1
}
192.168.5164:81 {
root * /var/www/mysite2
}
But I’d like to host both on a single port if that’s possible, to prevent the amount of ports open. I read that I can use headers to server different content, but could I also use the domain that is requesting the content? My reverse proxy caddyfile would look something like this with the different port setup:
docs.domain.tld {
reverse_proxy 192.168.5.164:80 {
header_up Host {upstream_hostport}
}
}
notes.domain.tld {
reverse_proxy 192.168.5.164:81 {
header_up Host {upstream_hostport}
}
}
Is there any way to use the domain that the reverse proxy uses to forward the request to server different content?