Middlewares

    Attached to the routers, pieces of middleware are a means of tweaking the requests before they are sent to your service (or before the answer from the services are sent to the clients).

    There are several available middleware in Traefik, some can modify the request, the headers, some are in charge of redirections, some add authentication, and so on.

    Middlewares that use the same protocol can be combined into chains to fit every scenario.

    Be aware of the concept of Providers Namespace described in the section. It also applies to Middlewares.

    Docker

    Kubernetes IngressRoute

    1. apiVersion: traefik.containo.us/v1alpha1
    2. kind: Middleware
    3. metadata:
    4. name: stripprefix
    5. spec:
    6. stripPrefix:
    7. prefixes:
    8. - /stripit
    9. ---
    10. apiVersion: traefik.containo.us/v1alpha1
    11. metadata:
    12. spec:
    13. # more fields...
    14. routes:
    15. # more fields...
    16. middlewares:
    17. - name: stripprefix

    Consul Catalog

    1. "labels": {
    2. "traefik.http.middlewares.foo-add-prefix.addprefix.prefix": "/foo",
    3. "traefik.http.routers.router1.middlewares": "foo-add-prefix@marathon"
    4. }

    Rancher

    File (YAML)

    1. # As YAML Configuration File
    2. http:
    3. service: myService
    4. middlewares:
    5. - "foo-add-prefix"
    6. rule: "Host(`example.com`)"
    7. middlewares:
    8. foo-add-prefix:
    9. addPrefix:
    10. prefix: "/foo"
    11. services:
    12. service1:
    13. loadBalancer:
    14. - url: "http://127.0.0.1:80"

    File (TOML)

    Available Middlewares

    A list of HTTP middlewares can be found .