Is there a middleware to remove whole path?

I have a traefik configured to route all traffic to a web host. When you access my.domain.com (not the real domain) it loads the page just fine. The angular app hosted there changes the path, but it all works peachy. However, if I try to refresh the page that is at my.domain.com/login, I get a 404. Is there a way remove the path entirely on the way to the web host?

I used a replacepath middleware in my example but it doesn't seem to do anything.

Relevant part of the compose file used in the stack deploy is below (without personal info):

version: "3.8"
services:
  proxy:
    image: traefik:v2.2
    command:
      - "--providers.docker.swarmMode=true"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--providers.docker.exposedByDefault=false"
      - "--providers.docker.network=ia_main"
      - "--log.level=DEBUG"
      - "--entryPoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entryPoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--entrypoints.websecure.http.tls.certResolver=myresolver"
      - "--certificatesresolvers.myresolver.acme.tlschallenge=true"
      - "--certificatesresolvers.myresolver.acme.email=<my-email-address>"
      - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
    ports:
      - 80:80
      - 443:443
      - 10080:8080
    volumes:
      - "acmestore:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    deploy:
      mode: replicated
      replicas: 3
      placement:
        max_replicas_per_node: 1
    networks:
      - main

  site:
    image: <my web host image>
    ports:
      - 11080:8043
    deploy:
      mode: replicated
      replicas: 3
      placement:
        max_replicas_per_node: 1
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.client.rule=Host(`my.domain.com`)"
        - "traefik.http.routers.client.service=service2"
        - "traefik.http.routers.client.priority=1"
        - "traefik.http.middlewares.site-delete-path.replacepath.path=/"
        - "traefik.http.services.service2.loadbalancer.server.port=8043"
        - "traefik.docker.network=ia_main"
    networks:
      - main
        
networks:
  main:
    driver: overlay
  
volumes:  
  acmestore:
    driver: local

You have defined the middleware but it is not in use by the router. You need a "traefik.http.routers.client.middlewares=site-delete-path label.

1 Like

This explained all my other issues actually. In this case, it didn't do what I wanted at first, but it worked fine after I did remove the slash like so:

    - "traefik.http.routers.client.middlewares=site-delete-path"
    - "traefik.http.middlewares.site-delete-path.replacepath.path="

Thanks for your help.

1 Like

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