Hello, I'm trying to replace caddy with traefik as my main reverse-proxy.
But I'm unable to do a simple PathPrefix / StripPrefix combination like i do in caddy with handle_path (https://caddyserver.com/docs/caddyfile/directives/handle_path)
My compose.yml
services:
traefik:
image: traefik:v3.1
command:
- --api.insecure=true
- --providers.docker
- --log.level=DEBUG
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
echo:
image: mendhak/http-https-echo
labels:
traefik.http.routers.echo.rule: Host("localhost")
echo-api:
image: mendhak/http-https-echo
labels:
traefik.http.routers.echo-api.rule: Host("localhost") && PathPrefix("/api")
traefik.http.routers.echo-api.middlewares": "strip-api"
traefik.http.middlewares.strip-api.stripprefix.prefixes": "/api"
echo-auth:
image: mendhak/http-https-echo
labels:
traefik.http.routers.echo-auth.rule: Host("localhost") && PathPrefix("/auth")
Now if i do a curl http://localhost/auth/123
the request is routed to the echo-auth container, so far so good. But the request that the auth container sees has the /auth
prefix still attached.
Now i want to remove this prefix for the echo-api container, but as soon as i do this, the requests are no longer routed to the echo-api container, instead they are catched by the echo container.
This is not what I'm expecting from this config, compare this caddy compose:
services:
caddy:
image: caddy:2
ports:
- "80:80"
volumes:
- "./Caddyfile:/etc/caddy/Caddyfile"
echo:
image: mendhak/http-https-echo
echo-api:
image: mendhak/http-https-echo
echo-auth:
image: mendhak/http-https-echo
With the following Caddyfile:
:80 {
handle /auth* {
reverse_proxy echo-auth:8080
}
handle_path /api* {
reverse_proxy echo-api:8080
}
reverse_proxy echo:8080
}
Here the handle_path
directive is stripping the /api
prefix and routes the requests to the echo-api container and not to the echo container.
Can you please help me with this problem, as this is an essential config for a client/server deployment with traefik.
Regards