Middleware does not exist! How can I fix this?

Hey Community,

I have a question regarding to the following error I get from docker-compose:

traefik_1   | time="2019-10-01T17:53:34Z" level=info msg="Configuration loaded from flags."
traefik_1   | time="2019-10-01T17:53:37Z" level=error msg="middleware \"customrequestheaders@docker\" does not exist" entryPointName=web routerName=delivery@docker
traefik_1   | time="2019-10-01T17:53:37Z" level=error msg="middleware \"customrequestheaders@docker\" does not exist" routerName=delivery@docker entryPointName=websecure
traefik_1   | time="2019-10-01T17:53:39Z" level=error msg="middleware \"customrequestheaders@docker\" does not exist" entryPointName=web routerName=delivery@docker
traefik_1   | time="2019-10-01T17:53:39Z" level=error msg="middleware \"customrequestheaders@docker\" does not exist" entryPointName=websecure routerName=delivery@docker

It tells me that my middleware is missing even though I defined it like this traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https in the following docker compose example. How do I go about fixing this?

version: '3.7'

services:
  traefik:
    image: traefik:v2.0
    ports:
      - 80:80
      - 443:443
    command:
      - --api=true
      - --providers.docker=true
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --certificatesresolvers.secure.acme.httpchallenge=true
      - --certificatesresolvers.secure.acme.httpchallenge.entrypoint=web
      - --certificatesresolvers.secure.acme.email=${MAIL_ADDRESS}
      - --certificatesresolvers.secure.acme.storage=/root/acme.json
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /root/acme.json:/root/acme.json
    labels:
      - traefik.http.routers.traefik.service=api@internal
      - traefik.http.routers.traefik.rule=Host(`monitor.example.org`)
      - traefik.http.routers.traefik.tls.certresolver=secure
      - traefik.http.routers.detour.rule=hostregexp(`{host:[a-z-.]+}`)
      - traefik.http.routers.detour.entrypoints=web
      - traefik.http.routers.detour.middlewares=redirect-to-https
      - traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https
      - traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https
  db:
    image: registry.example.com/repo/example/db:latest
    restart: always
    labels:
      - traefik.enable=false
  api:
    image: registry.example.com/repo/example/api:latest
    volumes:
      - /root/rsa.pem:/root/certs/rsa.pem
      - /root/rsa_pub.pem:/root/certs/rsa_pub.pem
    restart: always
    depends_on:
      - db
    environment:
      - MAIL_ADDRESS=${MAIL_ADDRESS}
      - MAIL_PASSWORD=${MAIL_PASSWORD}
      - MAIL_HOST=${MAIL_HOST}
    labels:
      - traefik.http.routers.api.rule=Host(`api.example.org`)
      - traefik.http.routers.api.tls.certresolver=secure
  delivery:
    image: registry.example.com/repo/example/delivery:latest
    volumes:
      - /root/rsa_pub.pem:/root/certs/rsa_pub.pem
    restart: always
    depends_on:
      - api
    labels:
      - traefik.http.routers.delivery.rule=Host(`delivery.example.org`)
      - traefik.http.routers.delivery.tls.certresolver=secure
      - traefik.http.routers.delivery.middlewares=customrequestheaders
  app:
    image: registry.example.com/repo/example/app:latest
    restart: always
    depends_on:
      - api
      - db
      - delivery
    labels:
      - traefik.http.routers.app.rule=Host(`example.org`,`www.example.org`)
      - traefik.http.routers.app.tls.certresolver=secure

Hi @thiloilg

In your configuraton :

      - traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https
      - traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https

the names of your middlewares are : redirect-to-https and sslheader
Please try :

  api:
    image: registry.example.com/repo/example/api:latest
    volumes:
      - /root/rsa.pem:/root/certs/rsa.pem
      - /root/rsa_pub.pem:/root/certs/rsa_pub.pem
    restart: always
    depends_on:
      - db
    environment:
      - MAIL_ADDRESS=${MAIL_ADDRESS}
      - MAIL_PASSWORD=${MAIL_PASSWORD}
      - MAIL_HOST=${MAIL_HOST}
    labels:
      - traefik.http.routers.api.rule=Host(`api.example.org`)
      - traefik.http.routers.api.tls.certresolver=secure
  delivery:
    image: registry.example.com/repo/example/delivery:latest
    volumes:
      - /root/rsa_pub.pem:/root/certs/rsa_pub.pem
    restart: always
    depends_on:
      - api
    labels:
      - traefik.http.routers.delivery.rule=Host(`delivery.example.org`)
      - traefik.http.routers.delivery.tls.certresolver=secure
      - traefik.http.routers.delivery.middlewares=sslheader
1 Like

@Ch1ch1 at was the problem. Thank you for your help!

1 Like