Caddyfile Subdomain with Multiple Proxies


(xoron) #1

i am new to using caddy and i am trying to figure out how to create a subdomain that can proxy to different endpoints based on path.

for example for a subdomain called pets in the domain my-website.com. i want to route the path /cats to serviceA and /dogs to serviceB.

i have tried this configuration:

pets.my-website.com {
    proxy /cats http://serviceA:80
    proxy /dogs http://serviceB:80
}

but this does not seem to work.

can anyone see what i am doing wrong?


(Paul Hodges) #2

You don’t say what you mean by “doesn’t work”. Could it be simply that you haven’t removed the “cats” or “dogs” from the URL you pass on? As in:

proxy /cats http://serviceA {
    without /cats
}
proxy /dogs http://serviceB {
    without /dogs
}

(xoron) #3

by “doesn’t work” i meant that the redirect doesn’t behave how i expect (i.e. redirect to the proxied endpoint).

i assumed it automatically removed “/cats” or “/dogs” from the URL by default. i have tried your method and now it works!

thanks!