Looking for help on how PathPrefix works (docker swarm)

I am looking for help on how PathPrefix works in Traefik 2.

I have two docker-compose files - traefik and a static web site - please see below. Everything works fine as long as there is no PathPrefix in the 2nd one - I can access pages at localhost. With PathPrefix I get 404 Page not found on localhost/serge. How would you explain that?

Thanks!

Traefik:

version: "3.3"

services:
  traefik:
    image: traefik:v2.2.1
    ports:
      - "80:80"
      - "8080:8080" # traefik dashboard
    command:
      - --api.insecure=true # set to 'false' on production
      - --api.dashboard=true # see https://docs.traefik.io/v2.0/operations/dashboard/#secure-mode for how to secure the dashboard
      - --api.debug=true # enable additional endpoints for debugging and profiling
      - --log.level=DEBUG # debug while we get it working, for more levels/info see https://docs.traefik.io/observability/logs/
      - --providers.docker=true
      - --providers.docker.endpoint=unix:///var/run/docker.sock
      - --providers.docker.swarmMode=true
      - --providers.docker.exposedByDefault=false
      - --providers.docker.network=proxy
      - --entrypoints.http.address=:80
    volumes:
      - letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - proxy

networks:
  proxy:
    external: true

volumes:
  letsencrypt:

and a static web site:

version: "3.3"

services:

  serge:
    image: yolkhovyy/serge:v1
    networks:
      - proxy
      - backend
    deploy:
      labels:
        - traefik.enable=true
        - traefik.http.routers.serge.rule=PathPrefix(`/serge`)
        - traefik.http.routers.serge.service=serge
        - traefik.http.routers.serge.entrypoints=http
        - traefik.http.services.serge.loadbalancer.server.port=80

networks:
  backend:
  proxy:
    external: true

The proxy network is created like this:

docker network create -d overlay proxy

Does /serge exist in your serge site container ?

If (as I suspect) you are expecting /serge to go to / in the container then you need to use stripPrefix middleware.

As your container is on two networks you should add traefik.docker.network to the serge labels.

Thanks a lot - that was the reason indeed.