404 when using PathPrefix rule

I am using the docker-compose file below, but for some reason the address hostname.tld/traefik is showing a plain 404 page not found text.

version: "3.3"

services:
  traefik:
    image: "traefik:v2.0.2"
    container_name: "traefik"
    restart: always
    networks:
      - traefik_proxy
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=true"
      - "--entrypoints.web.address=:8080"
      - "--providers.docker.watch=true"
    ports:
      - "443:443"
      - "8080:8080"
      - "80:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /home/bruno/traefik/traefik.toml:/traefik.toml
      - /home/bruno/traefik/acme.json:/acme.json
      - /home/bruno/traefik/error.log:/error.log
    labels:
      - "traefik.enable=true"
      - "traefik.port=8080"
      - "traefik.docker.network=traefik_proxy"
      - "traefik.http.routers.traefik.rule=Host(`hostname.tld`) && PathPrefix(`/traefik`)"
      - "traefik.http.routers.traefik.tls"
      - "traefik.http.middlewares.traefik.headers.SSLRedirect=true"
      - "traefik.http.middlewares.traefik.headers.STSSeconds=315360000"
      - "traefik.http.middlewares.traefik.headers.browserXSSFilter=true"
      - "traefik.http.middlewares.traefik.headers.contentTypeNosniff=true"
      - "traefik.http.middlewares.traefik.headers.forceSTSHeader=true"
      - "traefik.http.middlewares.traefik.headers.SSLHost=${DOMAIN_NAME}"
      - "traefik.http.middlewares.traefik.headers.STSIncludeSubdomains=true"
      - "traefik.http.middlewares.traefik.headers.STSPreload=true"

networks:
  traefik_proxy:
    external:
      name: traefik_proxy
  default:
    driver: bridge

However, in a similar setup, I am running a container on a specific host without any problems:

version: '2.2'

services:
  huggin:
    image: huginn/huginn
    restart: always
    container_name: huginn
    networks:
      - traefik_proxy
    ports:
      - 3000:3000
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.huginn.rule=Host(`huginn.${DOMAIN_NAME}`)"
      - "traefik.http.routers.huginn.tls"
      - "traefik.port=3000"
      - "traefik.docker.network=traefik_proxy"
      - "traefik.http.middlewares.huginn.headers.SSLRedirect=true"
      - "traefik.http.middlewares.huginn.headers.STSSeconds=315360000"
      - "traefik.http.middlewares.huginn.headers.browserXSSFilter=true"
      - "traefik.http.middlewares.huginn.headers.contentTypeNosniff=true"
      - "traefik.http.middlewares.huginn.headers.forceSTSHeader=true"
      - "traefik.http.middlewares.huginn.headers.SSLHost=${DOMAIN_NAME}"
      - "traefik.http.middlewares.huginn.headers.STSIncludeSubdomains=true"
      - "traefik.http.middlewares.huginn.headers.STSPreload=true"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/bruno/huginn/mysql:/var/lib/mysql 
    environment:
      - TZ=Europe/London

networks:
  traefik_proxy:
    external:
      name: traefik_proxy
  default:
    driver: bridge

I ran out of ideas and have been back and forth in the documentation. Does anyone have any ideas on what could cause this?

the labels are not flags so you have to define key=value

- "traefik.http.routers.traefik.tls=true"

Thank you @ldez, I missed that. But still, that doesn't solve the path prefix not working as expected. The difference now is that I get a "bad gateway" error.

This label is a v1 label so it's not compatible with v2.

the port 8080 is already used by the internal treafik entrypoint.

It's a middleware definition, you have to set the middleware on the router.


version: "3.3"

services:
  traefik:
    image: "traefik:v2.0.2"
    container_name: "traefik"
    restart: always
    networks:
      - traefik_proxy
    command:
      - "--api=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=true"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--providers.docker.watch=true"
    ports:
      - "443:443"
      - "8080:8080"
      - "80:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /home/bruno/traefik/traefik.toml:/traefik.toml
      - /home/bruno/traefik/acme.json:/acme.json
      - /home/bruno/traefik/error.log:/error.log
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_proxy"
      - "traefik.http.routers.traefik.rule=Host(`hostname.tld`)"
      - "traefik.http.routers.traefik.tls=true"
      - "traefik.http.routers.traefik.midddlewares=stsheaders"
      - "traefik.http.routers.traefik.service=api@internal"

      - "traefik.http.middlewares.stsheaders.headers.SSLRedirect=true"
      - "traefik.http.middlewares.stsheaders.headers.STSSeconds=315360000"
      - "traefik.http.middlewares.stsheaders.headers.browserXSSFilter=true"
      - "traefik.http.middlewares.stsheaders.headers.contentTypeNosniff=true"
      - "traefik.http.middlewares.stsheaders.headers.forceSTSHeader=true"
      - "traefik.http.middlewares.stsheaders.headers.SSLHost=${DOMAIN_NAME}"
      - "traefik.http.middlewares.stsheaders.headers.STSIncludeSubdomains=true"
      - "traefik.http.middlewares.stsheaders.headers.STSPreload=true"

networks:
  traefik_proxy:
    external:
      name: traefik_proxy
  default:
    driver: bridge

version: '2.2'

services:
  huggin:
    image: huginn/huginn
    restart: always
    container_name: huginn
    networks:
      - traefik_proxy
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_proxy"
      - "traefik.http.routers.huginn.rule=Host(`huginn.${DOMAIN_NAME}`)"
      - "traefik.http.routers.huginn.tls=true"
      - "traefik.http.routers.huginn.midddlewares=stsheaders"
      - "traefik.http.services.huginn.loadbalancer.server.port=3000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/bruno/huginn/mysql:/var/lib/mysql 
    environment:
      - TZ=Europe/London

networks:
  traefik_proxy:
    external:
      name: traefik_proxy
  default:
    driver: bridge
1 Like

@ldez thank you, this was a great help! :smiley: