I have Caddy running and serving requests for a single domain. Each service, including caddy, runs in its own container. All the services have access to the same docker network.
What I want is to be able to map url paths to different services. Something like:
What is the canonical way to implement reverse proxying for:
/whoami → iamfoo:5000
/whoami/bench → iamfoo:5000/bench
/whoami/bar → iamfoo:5000/bar
Keep in mind that I also want to statically serve the root domain path /.
I am going to have many more services coming. My strategy is going to be updating the Caddyfile and then do a -reload. Let me know if you have alternative suggestions for that.
I understand having dedicated subdomains is ideal but I don’t control the dns server. I have to go through a ticket system and the entries may take hours if not days to setup.
That is why I followed the path approach.
I am serving individual api endpoints so I should not have issues with this approach. If I need to serve html it will probably be single page apps and I can set the URLbase option.
Do you have any comments on better ways to dynamically create entries that map paths to other dockers services? Anyone has experience with this plugin?
CDP definitely works best with subdomains as well. You definitely can route by path as well with it, but it’s slightly more complicated to configure. It essentially just maps Docker labels to Caddyfile config, so you just need to figure out what Caddyfile you want for each service, then write the labels. CDP will merge sites with the same domain name.
What you need to decide is whether you need to strip the path prefix before proxying upstream, or not. If you do want to strip it, then handle_path is what you want to use. If not, then handle is what you want.
example.com {
# With path stripping
handle_path /whoami/* {
reverse_proxy whoami:5000
}
# No path stripping
handle /something-else/* {
reverse_proxy whatever:3000
}
handle {
# Fallback if none of the above handles matched
}
}