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.

    Provider Namespace

    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. kind: IngressRoute
    12. spec:
    13. # more fields...
    14. routes:
    15. # more fields...
    16. middlewares:
    17. - name: stripprefix

    Consul Catalog

    Marathon

    1. "labels": {
    2. "traefik.http.middlewares.foo-add-prefix.addprefix.prefix": "/foo",
    3. "traefik.http.routers.router1.middlewares": "[email protected]"
    4. }

    Rancher

    1. # As YAML Configuration File
    2. http:
    3. routers:
    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 .

    A list of TCP middlewares can be found here.


    Using Traefik for Business Applications?

    If you are using Traefik for commercial applications, consider the . You can use it as your: