Proxying two different base paths

1. Caddy version (caddy version): 1

d. My complete Caddyfile or JSON config:

:9080 {
    proxy /comments http://user-comment-api.cockpit-dev.svc:80 {
        insecure_skip_verify
    }
}

3. The problem I’m having:

I already have a proxy that is working for and API backend service.
So any requests now to mycadddy.com/comments/… will be forwarded to user-comment-api.cockpit-dev.svc:80/comments/… with /comments

I want to expose Swagger page of that API service.
Only one request with mycadddy.com/comments/swagger-ui.html should be forwarded to
user-comment-api.cockpit-dev.svc:80/swagger-ui.html , that is should not pass /comments path.

I tried something stupid and obviously it didn’t work

proxy /comments/swagger-ui.html http://user-comment-api.cockpit-dev.svc:80 {
insecure_skip_verify
without /comments
}

proxy /comments http://user-comment-api.cockpit-dev.svc:80 {
    insecure_skip_verify
    except /comments/swagger-ui.html
}

5. What I already tried:

I tried something stupid and obviously it didn’t work

proxy /comments/swagger-ui.html user-comment-api.cockpit-dev.svc:80 {
insecure_skip_verify
without /comments
}

proxy /comments user-comment-api.cockpit-dev.svc:80 {
    insecure_skip_verify
    except /comments/swagger-ui.html
}

And also looked into “except”, didn’t work

Caddy v1 is no longer actively maintained. I highly recommend you upgrade to Caddy v2.

Caddy v2 makes this sort of thing much easier with a generalized request matching system.

It would probably look like this:

handle /comments/swagger-ui.html {
	root * /path/to/dir
	uri strip_prefix /comments
	file_server
}

reverse_proxy /comments* http://user-comment-api.cockpit-dev.svc

This topic was automatically closed after 30 days. New replies are no longer allowed.