DEV Community

Tyler Smith
Tyler Smith

Posted on • Updated on • Originally published at caddyexamples.com

Routing multiple paths to a reverse proxy using Caddy

Sometimes your app will need to route a handful of paths to one service and all other paths to another. Caddy's named matchers allow you to define a set of path directives then route them all to a single reverse proxy.

:80 {
    bind 0.0.0.0
    encode zstd gzip
    @webapp {
        path /
        path /posts /posts/*
        path /tags /tags/*
        path /static /static/*
    }

    handle @webapp {
        reverse_proxy webapp:3000
    }
    handle {
        reverse_proxy wordpress:80
    }
}
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can omit the handle blocks:

:80 {
    bind 0.0.0.0
    encode zstd gzip
    @webapp {
        path /
        path /posts /posts/*
        path /tags /tags/*
        path /static /static/*
    }

    reverse_proxy @webapp webapp:3000
    reverse_proxy wordpress:80
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)