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
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: stripprefix
spec:
stripPrefix:
prefixes:
- /stripit
---
apiVersion: traefik.containo.us/v1alpha1
metadata:
spec:
# more fields...
routes:
# more fields...
middlewares:
- name: stripprefix
Consul Catalog
"labels": {
"traefik.http.middlewares.foo-add-prefix.addprefix.prefix": "/foo",
"traefik.http.routers.router1.middlewares": "foo-add-prefix@marathon"
}
Rancher
File (YAML)
# As YAML Configuration File
http:
service: myService
middlewares:
- "foo-add-prefix"
rule: "Host(`example.com`)"
middlewares:
foo-add-prefix:
addPrefix:
prefix: "/foo"
services:
service1:
loadBalancer:
- url: "http://127.0.0.1:80"
File (TOML)
Available Middlewares
A list of HTTP middlewares can be found .