Skip to content
DnsLister Forum

Where domain hunters compare notes

Caddyfile help re: reverse proxy simplification

Hi all, I've had my homelab running for over a year now and have had success in using caddy to reverse proxy all my services with TLS locally.

However, I'm still not well-versed on it all and mostly use guides alongside trial and error to sort things out. Is there a way to simplify my Caddyfile when it comes to repetitive reverse proxy blocks?

Below is a sample of my "external" Caddyfile that proxies request to my docker vm which has it's own Caddyfile that only trusts the external caddy IP and then proxies requests to individual dockers using docker networking (eliminates the need to expose any ports on the docker containers themselves)

### Global Options ### { http_port 80 https_port 443 servers { protocols h1 h2 h3 } email REDACTED } ### Reverse Proxy Configuration ### # WILDCARD *.example.com { tls { dns cloudflare REDACTED resolvers 1.1.1.1 } # SUBDOMAINS REVERSE-PROXIED TO vm-docker.internal @app1 host app1.example.com handle @app1 { reverse_proxy vm-docker.internal } @app2 host app2.example.com handle @app2 { reverse_proxy vm-docker.internal } @app3 host app3.example.com handle @app3 { reverse_proxy vm-docker.internal } 

Now what I'm imagining is something that simplifies the Caddyfile that may look something like this:

# SUBDOMAINS REVERSE-PROXIED TO vm-docker.internal $VARIABLE1 { app1 app2 app3 } @$VARIABLE1 host VARIABLE1.example.com handle @VARIABLE1 { reverse_proxy vm-docker.internal 

Am I making sense? Is there a way to have a SINGLE reverse proxy block and then substitute a variable from a predefined list?

Again, I don't know all the correct terms to use, so bear with me.

Additionally, if anybody has suggestions to improve my Caddyfile, please feel free to note them

Thanks

Source: r/selfhosted · by /u/sFooby

Leave a Reply

Your email address will not be published. Required fields are marked *