# Middleware "security-headers@file"

**URL:** <https://community.traefik.io/t/middleware-security-headers-file/18109>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [March 31, 2023, 5:08pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109 "2023-03-31T17:08:43Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [March 31, 2023, 5:08pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/1 "2023-03-31T17:08:43Z")

</div>

i keep getting this error on traefik dashboard:  
middleware "security-headers@file" does not exist  
can anyone assist

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [April 1, 2023, 6:09am UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/2 "2023-04-01T06:09:42Z")

</div>

Seems your middleware is not or not correctly set up. Is it placed in a dynamic config file, loaded by `provider.file` in static config?

Share your Traefik static and dynamic config, and `docker-compose.yml` if used.

Use 3 backticks or the `</>` button to format it.

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 2, 2023, 11:18am UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/3 "2023-04-02T11:18:43Z")

</div>

I ended up switching to nginx proxy manager as I couldn’t get my head round it

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 6, 2023, 12:52pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/4 "2023-04-06T12:52:02Z")

</div>

services:

```yml
  traefik:
    container_name: traefik
    image: traefik:latest
    ports:
      - 80:80
      - 443:443
      - 8080:8080 # Dashboard port
    volumes:
      - /opt/appdata/traefik/:/etc/traefik/
    networks:
      - proxy # rename this to your custom docker network
    labels:
      traefik.http.routers.api.rule: Host(`traefik.jhmcmedia.com`) # Define the subdomain for the traefik dashboard.
      traefik.http.routers.api.entryPoints: https # Set the Traefik entry point.
      traefik.http.routers.api.service: api@internal # Enable Traefik API.
      traefik.enable: true # Enable Traefik reverse proxy for the Traefik dashboard.
      traefik.http.routers.api.middlewares: auth@file
    environment:
      DOCKER_HOST: dockersocket
      CF_DNS_API_TOKEN: jnI3g6gXK209_l_62n0pqaMGu2wdV3ySkAP6y9z8
    restart: unless-stopped
    depends_on:
      - dockersocket

  dockersocket:
    container_name: dockersocket
    image: tecnativa/docker-socket-proxy
    ports:
      - 2375:2375
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - proxy
    environment:
      CONTAINERS: 1
      POST: 0
    privileged: true
    restart: unless-stopped

networks:
  proxy:
    driver: bridge
    external: true

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [April 6, 2023, 3:37pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/5 "2023-04-06T15:37:04Z")

</div>

Please use 3 backticks (before and after) or the `</>` button (when content is selected) to format your config.

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 7, 2023, 11:44am UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/8 "2023-04-07T11:44:41Z")

</div>

I did I used the \</\> button

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 7, 2023, 11:52am UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/9 "2023-04-07T11:52:45Z")

</div>

I use this example from ibracorp

```auto

http:
  middlewares:
    authentik:
      forwardauth:
        address: http://authentik-server:9000/outpost.goauthentik.io/auth/traefik
        trustForwardHeader: true
        authResponseHeaders:
          - X-authentik-username
          - X-authentik-groups
          - X-authentik-email
          - X-authentik-name
          - X-authentik-uid
          - X-authentik-jwt
          - X-authentik-meta-jwks
          - X-authentik-meta-outpost
          - X-authentik-meta-provider
          - X-authentik-meta-app
          - X-authentik-meta-version

  ## MIDDLEWARES ##
  middlewares:
    # Only Allow Local networks
    local-ipwhitelist:
      ipWhiteList:
        sourceRange: 
          - 127.0.0.1/32 # localhost
          - 192.168.1.1/24 # LAN Subnet
  
  
  
   

    # Security headers
    securityHeaders:
      headers:
        customResponseHeaders:
          X-Robots-Tag: "none,noarchive,nosnippet,notranslate,noimageindex"
          X-Forwarded-Proto: "https"
          server: ""
        customRequestHeaders:
          X-Forwarded-Proto: "https"
        sslProxyHeaders:
          X-Forwarded-Proto: "https"
        referrerPolicy: "same-origin"
        hostsProxyHeaders:
          - "X-Forwarded-Host"
        contentTypeNosniff: true
        browserXssFilter: true
        forceSTSHeader: true
        stsIncludeSubdomains: true
        stsSeconds: 63072000
        stsPreload: true
 
# Only use secure ciphers - https://ssl-config.mozilla.org/#server=traefik&version=2.6.0&config=intermediate&guideline=5.6              
tls:
  options:
    default:
      minVersion: VersionTLS12
      cipherSuites:
        - TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
        - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
        - TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
        - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
        - TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
        - TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [April 7, 2023, 9:06pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/10 "2023-04-07T21:06:25Z")

</div>

You use `http.middlewares` (the `middlewares` part) twice, maybe that is the issue.

Usually labels are used with `-` in front of each line.

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 7, 2023, 9:42pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/11 "2023-04-07T21:42:04Z")

</div>

Sorry that was an example I take the middle bit out and leave the top bit in

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [April 8, 2023, 6:35am UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/12 "2023-04-08T06:35:35Z")

</div>

Please share your full Traefik static and dynamic config, and `docker-compose.yml` if used.

If you only share pieces and those are not even from your deployment, then you waste everyones time here.

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 8, 2023, 11:02am UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/13 "2023-04-08T11:02:26Z")

</div>

```auto

http:
  middlewares:
    authentik:
      forwardauth:
        address: http://authentik-server:9000/outpost.goauthentik.io/auth/traefik
        trustForwardHeader: true
        authResponseHeaders:
          - X-authentik-username
          - X-authentik-groups
          - X-authentik-email
          - X-authentik-name
          - X-authentik-uid
          - X-authentik-jwt
          - X-authentik-meta-jwks
          - X-authentik-meta-outpost
          - X-authentik-meta-provider
          - X-authentik-meta-app
          - X-authentik-meta-version

   # Security headers
    securityHeaders:
      headers:
        customResponseHeaders:
          X-Robots-Tag: "none,noarchive,nosnippet,notranslate,noimageindex"
          X-Forwarded-Proto: "https"
          server: ""
        customRequestHeaders:
          X-Forwarded-Proto: "https"
        sslProxyHeaders:
          X-Forwarded-Proto: "https"
        referrerPolicy: "same-origin"
        hostsProxyHeaders:
          - "X-Forwarded-Host"
        contentTypeNosniff: true
        browserXssFilter: true
        forceSTSHeader: true
        stsIncludeSubdomains: true
        stsSeconds: 63072000
        stsPreload: true
 
# Only use secure ciphers - https://ssl-config.mozilla.org/#server=traefik&version=2.6.0&config=intermediate&guideline=5.6              
tls:
  options:
    default:
      minVersion: VersionTLS12
      cipherSuites:

```

Docker compose is same as above

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 12, 2023, 7:59pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/14 "2023-04-12T19:59:16Z")

</div>

Can anyone help? Still getting the error

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [April 12, 2023, 8:43pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/15 "2023-04-12T20:43:29Z")

</div>

Where is your Traefik static config? It contains for example `providers` and `entrypoints`.

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 12, 2023, 10:21pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/16 "2023-04-12T22:21:15Z")

</div>

this one is my config:

```auto

http:
  middlewares:
    authentik:
      forwardauth:
        address: http://authentik-server:9000/outpost.goauthentik.io/auth/traefik
        trustForwardHeader: true
        authResponseHeaders:
          - X-authentik-username
          - X-authentik-groups
          - X-authentik-email
          - X-authentik-name
          - X-authentik-uid
          - X-authentik-jwt
          - X-authentik-meta-jwks
          - X-authentik-meta-outpost
          - X-authentik-meta-provider
          - X-authentik-meta-app
          - X-authentik-meta-version

   # Security headers
    securityHeaders:
      headers:
        customResponseHeaders:
          X-Robots-Tag: "none,noarchive,nosnippet,notranslate,noimageindex"
          X-Forwarded-Proto: "https"
          server: ""
        customRequestHeaders:
          X-Forwarded-Proto: "https"
        sslProxyHeaders:
          X-Forwarded-Proto: "https"
        referrerPolicy: "same-origin"
        hostsProxyHeaders:
          - "X-Forwarded-Host"
        contentTypeNosniff: true
        browserXssFilter: true
        forceSTSHeader: true
        stsIncludeSubdomains: true
        stsSeconds: 63072000
        stsPreload: true
 
# Only use secure ciphers - https://ssl-config.mozilla.org/#server=traefik&version=2.6.0&config=intermediate&guideline=5.6              
tls:
  options:
    default:
      minVersion: VersionTLS12
      cipherSuites `

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [April 13, 2023, 7:34am UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/17 "2023-04-13T07:34:29Z")

</div>

Where is your Traefik **static** config? It contains for example **`providers`** and **`entrypoints`**.

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 13, 2023, 12:53pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/18 "2023-04-13T12:53:02Z")

</div>

```auto

global:
  checkNewVersion: true
  sendAnonymousUsage: false

serversTransport:
  insecureSkipVerify: true

entryPoints:
  # Not used in apps, but redirect everything from HTTP to HTTPS
  http:
    address: :80
    forwardedHeaders:
      trustedIPs: &trustedIps
        # Start of Clouflare public IP list for HTTP requests, remove this if you don't use it
        - 173.245.48.0/20
        - 103.21.244.0/22
        - 103.22.200.0/22
        - 103.31.4.0/22
        - 141.101.64.0/18
        - 108.162.192.0/18
        - 190.93.240.0/20
        - 188.114.96.0/20
        - 197.234.240.0/22
        - 198.41.128.0/17
        - 162.158.0.0/15
        - 104.16.0.0/12
        - 172.64.0.0/13
        - 131.0.72.0/22
        - 2400:cb00::/32
        - 2606:4700::/32
        - 2803:f800::/32
        - 2405:b500::/32
        - 2405:8100::/32
        - 2a06:98c0::/29
        - 2c0f:f248::/32
        # End of Cloudlare public IP list
    http:
      redirections:
        entryPoint:
          to: https
          scheme: https

  # HTTPS endpoint, with domain wildcard
  https:
    address: :443
    forwardedHeaders:
      # Reuse list of Cloudflare Trusted IP's above for HTTPS requests
      trustedIPs: *trustedIps
    http:
      tls:
        # Generate a wildcard domain certificate
        certResolver: letsencrypt
        domains:
          - main: YOURDOMAIN.COM
            sans:
              - '*.YOURDOMAIN.COM'
      middlewares:
        - securityHeaders@file

providers:
  providersThrottleDuration: 2s

  # File provider for connecting things that are outside of docker / defining middleware
  file:
    filename: /etc/traefik/fileConfig.yml
    watch: true

  # Docker provider for connecting all apps that are inside of the docker network
  docker:
    watch: true
    network: proxy # Add Your Docker Network Name Here
    # Default host rule to containername.domain.example
    defaultRule: "Host(`{{ index .Labels \"com.docker.compose.service\"}}.YOURDOMAIN.COM`)"
    swarmModeRefreshSeconds: 15s
    exposedByDefault: false
    #endpoint: "tcp://dockersocket:2375" # Uncomment if you are using docker socket proxy

# Enable traefik ui
api:
  dashboard: true
  insecure: true

# Log level INFO|DEBUG|ERROR
log:
  level: INFO

# Use letsencrypt to generate ssl serficiates
certificatesResolvers:
  letsencrypt:
    acme:
      email: YOUR@EMAIL.COM
      storage: /etc/traefik/acme.json
      dnsChallenge:
        provider: cloudflare
        # Used to make sure the dns challenge is propagated to the rights dns servers
        resolvers:
          - "1.1.1.1:53"
          - "1.0.0.1:53"

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [April 13, 2023, 2:00pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/19 "2023-04-13T14:00:29Z")

</div>

> [@mrnoname](#):
>
> `swarmModeRefreshSeconds`

Are you using Docker Swarm?

---

<div class="post-metadata">

**Author:** ![mrnoname](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mrnoname/32/6893_2.png) [@mrnoname](https://community.traefik.io/u/mrnoname)\
**Post date:** [April 13, 2023, 2:16pm UTC](https://community.traefik.io/t/middleware-security-headers-file/18109/20 "2023-04-13T14:16:07Z")

</div>

I use docker and docker compose I don’t know aba swarm as I’m very new to docker and traefik
