Traefik v2.6 PathPrefix won't work

Hello
I could not find a solution to the following problem - PathPrefix does not work, it gives a 404 error
when i type in browser http://example.com/myapp
So i have docker-compose.yml for myapp (node.js) with such entries:

version: "3.8"

networks:
  web:
    external: true
  internal:
    external: false

services:
  traefik:
    image: "traefik:v2.6.0"
    container_name: traefik
    hostname: traefik
    command:
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --providers.docker
      - --providers.docker.exposedByDefault=false
      - --api
      - --certificatesresolvers.le.acme.email=admin@example.com
      - --certificatesresolvers.le.acme.storage=./shared/acme.json
      - --certificatesresolvers.le.acme.tlschallenge=true
      - --log=true
      - --accessLog
      - --log.level=DEBUG
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./shared:/shared
    labels:
      - traefik.enable=true
      # Dashboard
      - traefik.http.routers.traefik.rule=Host(`dash.example.com`)
      - traefik.http.routers.traefik.service=api@internal
      - traefik.http.routers.traefik.tls=true
      - traefik.http.routers.traefik.tls.certresolver=le
      - traefik.http.routers.traefik.entrypoints=websecure
      - traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https
    restart: unless-stopped
    networks:
      - web
      - internal

  myapp:
    platform: linux/x86_64
    container_name: app
    image: app:latest
    depends_on:
      - traefik
    ports:
      - 3333:3333
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.myapp.rule=Host(`example.com`) && PathPrefix(`/myapp`)"
      - "traefik.http.routers.myapp.middlewares=myapp-stripprefix"
      - "traefik.http.middlewares.myapp-stripprefix.stripprefix.prefix=/myapp"
      - "traefik.http.routers.myapp.service=myapp@docker"
      - "traefik.http.services.myapp.loadbalancer.server.port=3333"
    restart: unless-stopped
    networks:
       - internal
       - web


Web browser showed "404 page not found"
When I do curl http://127.0.0.1:3333 myapp give response

When I commented out the lines:
- "traefik.http.routers.myapp.middlewares=myapp-stripprefix"
- "traefik.http.middlewares.myapp-stripprefix.stripprefix.prefix=/myapp"
Web browser showed "Cannot GET /myapp"

When i use this string - "traefik.http.routers.myapp.rule=Host(example.com)"
without prefix - all working.

Many thanks for your help.

Solved
Fixed some error, and now worked

      - "traefik.enable=true"
      - "traefik.http.routers.myapp.rule=Host(`example.com`) && PathPrefix(`/myapp`)"
      - "traefik.http.middlewares.myapp-stripprefix.stripprefix.prefixes=/myapp"
      - "traefik.http.routers.myapp.middlewares=myapp-stripprefix@docker"

1 Like

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