Can I use regex in http.proxy 'from'/'to' syntax?

(Nota Xiao) #1

I use caddy as a reverse proxy. What I want to do is proxying my.domain/xxx/yyy to xxx.destination.domain/yyy. Here xxx and yyy is not sure. So I am wondering if I could use wildcards and capture groups in the Caddyfile.
For example, I can write as this with nginx:

server_name  my.domain;
location ~* ^/(.*)/(.*)$ {
        proxy_pass https://$1.destination.domain/$2;

Does caddy support this feature?

(Matthew Fay) #2

Hi @Nota,

I think you could manage it by abusing rewrites, if either the hostname or the URI were static… but not with both being dynamic.

The proxy directive doesn’t support dynamic backends or regex capture/substitution at the moment, but it’s an often-requested feature. Here’s the relevant Github issue:

(Nota Xiao) #3

Thanks. Using rewrites seems practical.

(system) #4

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