Different container behind "/" and "/api/" - how?

Struggling with some configuration, maybe someone has an idea.

Following situation, I have an Angular app in an nginx container behind root path "/".
Configured with following docker-compose labels:

- "traefik.enable=true"
- "traefik.http.routers.frontend.rule=Host(`app.server.com`)"
- "traefik.http.routers.frontend.tls.certresolver=leresolver"
- "traefik.http.routers.frontend.entrypoints=websecure"

Now I want to have an api in form as an Python container behind "/api/".
Configured with following docker-compose labels:

- "traefik.enable=true"
- "traefik.http.routers.app-api.rule=Host(`app.server.com`) && (PathPrefix(`/api{regex:$$|/.*}`))"
- "traefik.http.routers.app-api.entrypoints=websecure"

On the Traefik dashboard it looks like everything is correct configured, but when I try to call app.server.com/api/ the nginx behind "/" gets the request and throws a 404.

Where is my misconfiguration / misunderstanding?

- "traefik.http.routers.app-api.rule=Host(`app.server.com`) && PathPrefix(`/api`)"

Anything else not prefixed with /api will go to the frontend rule.

Thanks for your answer. Tried that already, without the regex, but still the nginx from the frontend gets the request.

Does this service also have the TLS option in it's labels ?

No, as far as I understood it, it's not necessary, because the "/" rule already creates the certificate for the domain. You think, that may be the issue?

For sure.

Your 2nd router app-api will be plain http on entrypoint websecure.

Thank you!! Can you explain that to me? Why do I have to add the certresolver also to a subfolder? That makes no sense for me.

So I added following line to the "/api/" docker-compose:

- "traefik.http.routers.app-api.tls.certresolver=leresolver"

... and it worked. Thanks to @cakiwi

1 Like

It is not a subfolder, you are creating an entirely different router.

It is possible to set an entrypoint tls as well as other options by default.


It probably will be useful to familiarise yourself with some core concepts. Do not just read the overview, read also all the subsections. As cakiwi noted, there is not concept of "subfolder" in traefik, there are routers and services, and naturally you do need a separate router in your use case.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.