# Syntax for multiple middlewares (HTTPS redirect and auth)

**URL:** <https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663>\
**Category:** Traefik v2\
**Tags:** middleware, docker\
**Created:** [September 18, 2019, 8:32am UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663 "2019-09-18T08:32:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonszu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/simonszu/32/708_2.png) [@simonszu](https://community.traefik.io/u/simonszu)\
**Post date:** [September 18, 2019, 8:32am UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663/1 "2019-09-18T08:32:16Z")

</div>

Hi,

i'm currently in the process of migrating from v1 to v2. This is a working v1 example for docker i have:

```auto
      traefik.backend: resilio
      traefik.enable: "true"
      traefik.frontend.rule: Host:resilio.mytld
      traefik.port: "8888" 
      traefik.frontend.auth.basic.users=xxxxxx:xxxxxxxx

```

I cannot figure it out how to migrate this to v2. Currently my attempt looks like this:

```auto
     traefik.http.routers.web.rule: Host('resilio.mytld')
     traefik.http.routers.web.entrypoints: web
     traefik.http.routers.web.middlewares: redirect@file
     traefik.http.routers.web-secured.rule: Host('resilio.mytld')
     traefik.http.routers.web-secured.entrypoints: web-secure
     traefik.http.routers.web-secured.tls: true
     traefik.http.routers.web-secured.service: resilio
     traefik.http.services.resilio.loadbalancer.server.port: 8888

```

This should work for the HTTPS router pointing to the service listening on HTTPS, shouldn't it?

However, i have two questions:

1. What is the proper syntax for adding multiple middlewares to a router with labels for a docker container definition? The documentation says: A list. Since i am defining the containers via the ansible `docker_container` module, one could assume a list in yaml style, but that cannot apply for a "simple" `docker run` command.
2. What does the `redirect@file` middleware do? It is copypasted from [the docs](https://docs.traefik.io/migration/v1-to-v2/#http-to-https-redirection-is-now-configured-on-routers), but according to [the docs](https://docs.traefik.io/middlewares/overview/) there does not exist a `redirect@file` middleware. Wouldn't a `RedirectScheme` be more appropriate, like described in the lists of middlewares?

Maybe someone can help me accomplish my goal of translating the above v1 snippet to a v2 snippet which does the same, so i can adapt it to my other services.

---

<div class="post-metadata">

**Author:** ![EugenMayer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/eugenmayer/32/694_2.png) [@EugenMayer](https://community.traefik.io/u/EugenMayer)\
**Post date:** [September 18, 2019, 9:35am UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663/2 "2019-09-18T09:35:22Z")

</div>

I had a very similar question here [Global http to https redirect in v2](https://community.containo.us/t/global-http-to-https-redirect-in-v2/1658/2) .. but not label related. Similar assumption but yet similar unsure 🙂

---

<div class="post-metadata">

**Author:** ![emce](https://avatars.discourse-cdn.com/v4/letter/e/9fc29f/32.png) [@emce](https://community.traefik.io/u/emce)\
**Post date:** [September 18, 2019, 12:08pm UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663/3 "2019-09-18T12:08:56Z")

</div>

I'm also still learning and deciphering the documentation, but I think this will help...

First, the @file syntax is a [provider](https://docs.traefik.io/providers/file/) reference to dynamic file configuration. In order for your labels to work, you'd load a dynamic configuration that contained something like the following:

```auto
[http.middlewares]
  [http.middlewares.redirect.redirectscheme]
    scheme = "https"
  [http.middlewares.auth.basicAuth]
    users = [
      "user:$$encodedpassword123$$",
    ]

```

Note that "redirect" and "auth" are arbitrary names we're using in this example that reference the middleware configuration.

Then, because I don't believe they're referring to a YAML list rather than a literal list, in order to load both auth and redirect middlewares, I believe you'd do:

```auto
     - "traefik.http.routers.web.rule: Host('resilio.mytld')"
     - "traefik.http.routers.web.entrypoints: web"
     - "traefik.http.routers.web.middlewares: redirect@file, auth@file"
     - "traefik.http.routers.web-secured.rule: Host('resilio.mytld')"
     - "traefik.http.routers.web-secured.entrypoints: web-secure"
     - "traefik.http.routers.web-secured.tls: true"
     - "traefik.http.routers.web-secured.service: resilio"
     - "traefik.http.services.resilio.loadbalancer.server.port: 8888"

```

That said, you may want to attach your auth middleware to your secured route?

Again, any part of this may be incorrect as the docs have felt incomplete and a bit hard to follow for me thus far, but hopefully it helps you along.

---

<div class="post-metadata">

**Author:** ![mpl](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mpl](https://community.traefik.io/u/mpl)\
**Post date:** [September 18, 2019, 12:42pm UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663/4 "2019-09-18T12:42:31Z")

</div>

@emce No, you got it right. 🙂 redirect@file is indeed how you refer to a middleware arbitrarily named redirect, which would be defined for the file provider, i.e. in a dynamic file configuration.

Also, yes, a comma separated list should be the syntax to refer to a list of middlewares in a router, as confirmed in: [https://docs.traefik.io/v2.0/reference/dynamic-configuration/docker/](https://docs.traefik.io/v2.0/reference/dynamic-configuration/docker/)

---

<div class="post-metadata">

**Author:** ![simonszu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/simonszu/32/708_2.png) [@simonszu](https://community.traefik.io/u/simonszu)\
**Post date:** [September 19, 2019, 8:42am UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663/5 "2019-09-19T08:42:57Z")

</div>

Thanks for your answers. They have helped me a bit. However, currently i am struggling with the dynamic file configuration.  
I have created a directory called `conf.d` and mounted it in `/conf.d` in the traefik container.  
I reference this directory in the traefik.yaml with the following snippet:

```auto
providers:
  file:
    directory: /conf.d
    watch: true

```

Inside this directory there is a file called redirect.yaml with the following content:

```auto
http:
  middlewares:
    redirect:
      redirectScheme:
        scheme: https

```

And these are the labels with whom i want to make the traefik dashboard available via HTTP-to-HTTPS redirect and basic auth:

```auto
   labels:
      traefik.enable: "true"
      traefik.http.routers.api.rule: "Host(`traefik.mydomain`)"
      traefik.http.routers.api.middlewares: "redirect@file"
      traefik.http.routers.api-secured.rule: "Host(`traefik.mydomain`)"
      traefik.http.routers.api-secured.middlewares: "auth"
      traefik.http.routers.api-secured.service: "api@internal"
      traefik.http.middlewares.auth.basicauth.users: "user.$pass$"

```

I already was successful with accessing the dashboard via plaintext HTTP, but the currrent configuration gives me these errors:

```auto
time="2019-09-19T08:37:26Z" level=info msg="Configuration loaded from file: /traefik.yaml"
time="2019-09-19T08:37:27Z" level=error msg="middleware \"redirect@file\" does not exist" entryPointName=web routerName=api@docker
time="2019-09-19T08:37:27Z" level=error msg="middleware \"redirect@file\" does not exist" entryPointName=web-secure routerName=api@docker
time="2019-09-19T08:37:27Z" level=error msg="middleware \"redirect@file\" does not exist" entryPointName=traefik routerName=api@docker

```

Why?

---

<div class="post-metadata">

**Author:** ![simonszu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/simonszu/32/708_2.png) [@simonszu](https://community.traefik.io/u/simonszu)\
**Post date:** [September 19, 2019, 11:28am UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663/6 "2019-09-19T11:28:52Z")

</div>

I fixed it. I didn't notice i already had a provider section for docker. Now everything's fine. Next step: Catchall HTTPS redirect, but i'll look into @EugenMayer s thread for that.

---

<div class="post-metadata">

**Author:** ![jjaarddev](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jjaarddev/32/6021_2.png) [@jjaarddev](https://community.traefik.io/u/jjaarddev)\
**Post date:** [October 7, 2022, 4:59pm UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663/7 "2022-10-07T16:59:04Z")

</div>

Just to ask - is it better to configure redirects to http via ENTRYPOINT or MIDDLEWARE ? Are there any advantages / disadvantages?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [October 10, 2022, 4:59pm UTC](https://community.traefik.io/t/syntax-for-multiple-middlewares-https-redirect-and-auth/1663/8 "2022-10-10T16:59:17Z")

</div>

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