lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
2.85k stars 169 forks source link

Using the upstreams template in a snippet with arguments #634

Open grenadilla opened 3 months ago

grenadilla commented 3 months ago

I'm trying to write a snippet which takes in an argument and passes it as the port to the upstreams template. I've tried a few variations:

caddy: (proxy_tls)
caddy.tls: "certificate.pem private.key.pem"
caddy.reverse_proxy: "{{upstreams {args[0]}}}"

caddy.reverse_proxy.transport: http
caddy.reverse_proxy.transport.tls:
caddy.reverse_proxy.transport.tls_insecure_skip_verify:

this errors encountering an unexpected '{' character and the snippet was not able to be parsed.

Next I tried

caddy: (proxy_tls)
caddy.tls: "certificate.pem private.key.pem"
caddy.reverse_proxy: "{{upstreams `{args[0]}`}}"

caddy.reverse_proxy.transport: http
caddy.reverse_proxy.transport.tls:
caddy.reverse_proxy.transport.tls_insecure_skip_verify:

which results in a snippet which is able to be parsed. However, it seems to interpret the argument as the schema instead of the port, so it will proxy urls from 80://127.0.0.1 instead of 127.0.0.1:80.

I'm wondering if there's a way to use both the upstreams template and snippet arguments at the same time?

The result I want is

reverse_proxy ip:port {
  transport http {
    tls <insert certificate here>
    tls_insecure_verify
  }
}

as I'm proxying to an https endpoint.