# Docker Traefik Headers not set

**URL:** <https://community.traefik.io/t/docker-traefik-headers-not-set/7934>\
**Category:** Traefik v2\
**Tags:** docker, middleware\
**Created:** [September 28, 2020, 2:05pm UTC](https://community.traefik.io/t/docker-traefik-headers-not-set/7934 "2020-09-28T14:05:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![deeztek](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/deeztek/32/1633_2.png) [@deeztek](https://community.traefik.io/u/deeztek)\
**Post date:** [September 28, 2020, 2:05pm UTC](https://community.traefik.io/t/docker-traefik-headers-not-set/7934/1 "2020-09-28T14:05:46Z")

</div>

I can't seem to get Traefik to set headers:

I have the following labels in my docker-compose.yml file:

```auto
services:
  nextcloud:
    image: 'nextcloud:latest'
    container_name: nextcloud
    build: .
    networks:
      - proxy
      - nextcloud

    volumes:
      - nextcloud:/var/www/html

    environment:
      - TZ=$TIMEZONE
      - MYSQL_HOST=$MYSQL_HOST
      - MYSQL_DATABASE=$MYSQL_DATABASE
      - MYSQL_USER=$MYSQL_USER
      - MYSQL_PASSWORD=$MYSQL_PASSWORD
      - REDIS_HOST=nextcloud_redis
      - REDIS_HOST_PASSWORD=$REDIS_PASSWORD
      - NEXTCLOUD_ADMIN_USER=$NEXTCLOUD_ADMIN_USER
      - NEXTCLOUD_ADMIN_PASSWORD=$NEXTCLOUD_ADMIN_PASSWORD
      - SMTP_HOST=$SMTP_HOST
      - SMTP_SECURE=$SMTP_SECURE
      - SMTP_PORT=$SMTP_PORT
      - SMTP_AUTHTYPE=$SMTP_AUTHTYPE
      - SMTP_NAME=$SMTP_NAME
      - SMTP_PASSWORD=$SMTP_PASSWORD
      - MAIL_FROM_ADDRESS=$MAIL_FROM_ADDRESS
      - MAIL_DOMAIN=$MAIL_DOMAIN
      - APACHE_DISABLE_REWRITE_IP=1
      - TRUSTED_PROXIES=192.168.80.0/20

    depends_on:
      - nextcloud_redis
    restart: unless-stopped

labels:
  - "traefik.enable=true"
  - "traefik.http.routers.cloud.entrypoints=http"
  - "traefik.http.routers.cloud.rule=Host(`$HOST.$DOMAIN`)"
  - "traefik.http.middlewares.cloud-https-redirect.redirectscheme.scheme=https"
  - "traefik.http.routers.cloud.middlewares=cloud-https-redirect"
  - "traefik.http.routers.cloud-secure.entrypoints=https"
  - "traefik.http.routers.cloud-secure.rule=Host(`$HOST.$DOMAIN`)"
  - "traefik.http.routers.cloud-secure.tls=true"
  - "traefik.http.routers.cloud-secure.tls.certresolver=le"
  - "traefik.http.routers.cloud-secure.service=cloud"
  - "traefik.http.services.cloud.loadbalancer.server.port=80"
  - "traefik.docker.network=proxy"
  - "traefik.http.middlewares.cloud.headers.customFrameOptionsValue=SAMEORIGIN"
  - "traefik.http.middlewares.cloud.headers.framedeny=true"
  - "traefik.http.middlewares.cloud.headers.sslredirect=true"
  - "traefik.http.middlewares.cloud.headers.STSIncludeSubdomains=true"
  - "traefik.http.middlewares.cloud.headers.STSPreload=true"
  - "traefik.http.middlewares.cloud.headers.STSSeconds=315360000"
  - "traefik.http.middlewares.cloud.headers.forceSTSHeader=true"
  - "traefik.http.middlewares.cloud.headers.sslProxyHeaders.X-Forwarded-Proto=https"
  - "traefik.http.middlewares.cloud-dav.replacepathregex.regex=^/.well-known/ca(l|rd)dav"
  - "traefik.http.middlewares.cloud-dav.replacepathregex.replacement=/remote.php/dav/"

```

I have also verified under Traefik HTTP Middlewares that the cloud@docker is showing the following:

```auto
STS SECONDS 315360000
STS INCLUDE SUBDOMAINS True
STS PRELOAD True
FORCE STS HEADER True
FRAME DENY True

```

Yet I'm not seeing those response headers. I'm sure I'm doing something stupid but I can't figure out what.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [September 28, 2020, 2:42pm UTC](https://community.traefik.io/t/docker-traefik-headers-not-set/7934/2 "2020-09-28T14:42:22Z")

</div>

Hi @deeztek

I only see one router with a middlewares statement.  
So the middleware is defined but not referenced.

> [@deeztek](#):
>
> ` - "traefik.http.routers.cloud.middlewares=cloud-https-redirect"`

---

<div class="post-metadata">

**Author:** ![deeztek](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/deeztek/32/1633_2.png) [@deeztek](https://community.traefik.io/u/deeztek)\
**Post date:** [September 28, 2020, 3:22pm UTC](https://community.traefik.io/t/docker-traefik-headers-not-set/7934/3 "2020-09-28T15:22:32Z")

</div>

I guess I'm confused. For example, the middleware below should be like this?

`- "traefik.http.middlewares.cloud-https-redirect.headers.STSSeconds=315360000"`

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [September 28, 2020, 5:51pm UTC](https://community.traefik.io/t/docker-traefik-headers-not-set/7934/4 "2020-09-28T17:51:34Z")

</div>

So you have defined the middleware correctly, you see it in the traefik dashboard.

The problem is no routers are using it. You likely want to add this label:

```auto
- "traefik.http.routers.cloud-secure.middlewares=cloud"

```

This line is superfluous as this is the container the route applies to.

```auto
  - "traefik.http.routers.cloud-secure.service=cloud"

```

---

<div class="post-metadata">

**Author:** ![deeztek](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/deeztek/32/1633_2.png) [@deeztek](https://community.traefik.io/u/deeztek)\
**Post date:** [September 28, 2020, 7:28pm UTC](https://community.traefik.io/t/docker-traefik-headers-not-set/7934/5 "2020-09-28T19:28:23Z")

</div>

Adding the below label as you suggested:

`- "traefik.http.routers.cloud-secure.middlewares=cloud"`

Breaks the container with the following error:

`cannot create middleware: multi-types middleware not supported, consider declaring two different pieces of middleware instead`

I'm guessing because the following label already exists:

` - "traefik.http.routers.cloud.middlewares=cloud-https-redirect"`

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [September 28, 2020, 7:45pm UTC](https://community.traefik.io/t/docker-traefik-headers-not-set/7934/6 "2020-09-28T19:45:18Z")

</div>

> [@deeztek](#):
>
> I'm guessing because the following label already exists:
> 
> ` - "traefik.http.routers.cloud.middlewares=cloud-https-redirect"`

That is on a different router (cloud) it doesn't look like a conflict.

> [@deeztek](#):
>
> Breaks the container with the following error:
> 
> `cannot create middleware: multi-types middleware not supported, consider declaring two different pieces of middleware instead`

This sounds like there is an additional middleware type being added on a middleware definition. There might be additional context with that error that shows which one.

Were the any other changes made? What does the full labels section look like now ?

---

<div class="post-metadata">

**Author:** ![zespri](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/zespri/32/310_2.png) [@zespri](https://community.traefik.io/u/zespri)\
**Post date:** [October 1, 2020, 10:21am UTC](https://community.traefik.io/t/docker-traefik-headers-not-set/7934/7 "2020-10-01T10:21:51Z")

</div>

If you have two labels starting with

- traefik.http.middlewares.name.addprefix
- traefik.http.middlewares.name.basicauth

where `addprefix` and `basicauth` are some arbitrary middlewares, and the `name` is the same middleware (instance) name you will get the error you are seeing. make sure that you do not have anything like that (even across different containers)
