Skip to main content

Middlewares

Tweaking the Request Attached to routers, pieces of middleware are a means of tweaking 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 NamespaceBe aware of the concept of Providers Namespace. It also applies to Middlewares.

Configuration Example

# As a Docker Label
whoami:
  # A container that exposes an API to show its IP address
  image: traefik/whoami
  labels:
    # Create a middleware named `foo-add-prefix`
    - "traefik.http.middlewares.foo-add-prefix.addprefix.prefix=/foo"
    # Apply the middleware named `foo-add-prefix` to the router named `router1`
    - "traefik.http.routers.router1.middlewares=foo-add-prefix@docker"

Available Middlewares

Traefik provides middlewares for both HTTP and TCP protocols:

Build docs developers (and LLMs) love