May caddy do dynamic reverse proxy?

such as proxy a.publicdomain.com a.internetdomain.net

*.publicdomain.com {
proxy *.publicdomain.com *.internetdomain.net
}

can caddy do that?

Hi @zhangyc,

Unfortunately, the only substitutions available to the proxy directive are placeholders and environmental variables.

It’s not possible to proxy based on part of the domain name. The closest you could get is proxying based on a query key/value:

(see Matt Holt’s post below)

Are you saying subdomain proxy isn’t available at all? Or in other words, each subdomain would need to a separate entry?

One of the placeholder is “{host}” so would this be valid?

*.example.com {
     proxy / {host}:5000
}

@agrothe Placeholders can’t be used in the proxy destinations/backends, as far as I know. Maybe there was a change a while ago and I forgot about it or a recent change that I didn’t notice? But backends are static, meaning they can’t be changed per request (it’s both a feature and a limitation).

Thanks for reply.
I checked the code , that is true, only support static backends proxy.
the backend proxy pool is init when start caddy.
If I want change proxy per request, need change upstream.select(r *request) .

If want request changed backend proxy, Need maintain a global backend proxy pools. and select backend proxy by request’s host.

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