Issue with unexpected pathPrefix behavior not redirecting

I'm trying to make a dynamic route file that has a main service on a subdomain and have requests to /api redirect to a dedicated api container. I added pathPrefix rules and set priorities but all requests including the /api requests go to the main container.

Can anyone help me see what I'm doing wrong? I've been troubleshooting this for over a week

http:
  services:
    app:
      loadBalancer:
        servers:
          - url: "http://{service-ip}:{main-service-port}"

    app-api:
      loadBalancer:
        servers:
          - url: "http://{service-ip}:{api-service-port}"

  middlewares:
    redirect-to-https:
      redirectScheme:
        scheme: "https"
    gzip:
      app: true

  routers:
    http-app:
      entryPoints:
        - http
      middlewares:
        - redirect-to-https
      rule: "Host(`{host-domain}`)"
      service: "app"
      priority: 10

    https-app:
      entryPoints:
        - https
      middlewares:
        - gzip
      rule: "Host(`{host-domain}`)"
      service: "app"
      priority: 20
      tls:
        certResolver: "letsencrypt"

    app-api:
      entryPoints:
        - http
        - https
      rule: "Host(`{host-domain}`) && PathPrefix(`/api/`)"
      service: "app-api"
      priority: 30

Declaration of routers and services belong into a dynamic config file, which is loaded in static config with providers.file.

I recommend to place http-to-https redirects and enable TLS globally on entrypoints, see simple Traefik example.

Another thing you may try is to enclose the argument to the rule in parenthesis. I have found that Traefik at times follows unexpected evaluation of expressions.

thanks for the tip, that will help me clean up my configs.

I fixed the issue, apparently my api rule was being discarded since all requests were being sent over https but requests to /api weren't matching the same tls auth

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