2022-04-15 13:44:08 +00:00
|
|
|
---
|
|
|
|
title: "Traefik Proxy HTTP Middleware Overview"
|
|
|
|
description: "Read the official Traefik Proxy documentation for an overview of the available HTTP middleware."
|
|
|
|
---
|
|
|
|
|
2021-06-11 13:30:05 +00:00
|
|
|
# HTTP Middlewares
|
|
|
|
|
|
|
|
Controlling connections
|
|
|
|
{: .subtitle }
|
|
|
|
|
|
|
|
![Overview](../../assets/img/middleware/overview.png)
|
|
|
|
|
|
|
|
## Configuration Example
|
|
|
|
|
|
|
|
```yaml tab="Docker"
|
|
|
|
# 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"
|
|
|
|
```
|
|
|
|
|
|
|
|
```yaml tab="Kubernetes IngressRoute"
|
|
|
|
# As a Kubernetes Traefik IngressRoute
|
|
|
|
apiVersion: apiextensions.k8s.io/v1beta1
|
|
|
|
kind: CustomResourceDefinition
|
|
|
|
metadata:
|
|
|
|
name: middlewares.traefik.containo.us
|
|
|
|
spec:
|
|
|
|
group: traefik.containo.us
|
|
|
|
version: v1alpha1
|
|
|
|
names:
|
|
|
|
kind: Middleware
|
|
|
|
plural: middlewares
|
|
|
|
singular: middleware
|
|
|
|
scope: Namespaced
|
|
|
|
|
|
|
|
---
|
|
|
|
apiVersion: traefik.containo.us/v1alpha1
|
|
|
|
kind: Middleware
|
|
|
|
metadata:
|
|
|
|
name: stripprefix
|
|
|
|
spec:
|
|
|
|
stripPrefix:
|
|
|
|
prefixes:
|
|
|
|
- /stripit
|
|
|
|
|
|
|
|
---
|
|
|
|
apiVersion: traefik.containo.us/v1alpha1
|
|
|
|
kind: IngressRoute
|
|
|
|
metadata:
|
|
|
|
name: ingressroute
|
|
|
|
spec:
|
|
|
|
# more fields...
|
|
|
|
routes:
|
|
|
|
# more fields...
|
|
|
|
middlewares:
|
|
|
|
- name: stripprefix
|
|
|
|
```
|
|
|
|
|
|
|
|
```yaml tab="Consul Catalog"
|
|
|
|
# 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@consulcatalog"
|
|
|
|
```
|
|
|
|
|
|
|
|
```json tab="Marathon"
|
|
|
|
"labels": {
|
|
|
|
"traefik.http.middlewares.foo-add-prefix.addprefix.prefix": "/foo",
|
|
|
|
"traefik.http.routers.router1.middlewares": "foo-add-prefix@marathon"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```toml tab="File (TOML)"
|
|
|
|
# As TOML Configuration File
|
|
|
|
[http.routers]
|
|
|
|
[http.routers.router1]
|
2021-12-17 15:24:06 +00:00
|
|
|
service = "service1"
|
2021-06-11 13:30:05 +00:00
|
|
|
middlewares = ["foo-add-prefix"]
|
|
|
|
rule = "Host(`example.com`)"
|
|
|
|
|
|
|
|
[http.middlewares]
|
|
|
|
[http.middlewares.foo-add-prefix.addPrefix]
|
|
|
|
prefix = "/foo"
|
|
|
|
|
|
|
|
[http.services]
|
|
|
|
[http.services.service1]
|
|
|
|
[http.services.service1.loadBalancer]
|
|
|
|
|
|
|
|
[[http.services.service1.loadBalancer.servers]]
|
|
|
|
url = "http://127.0.0.1:80"
|
|
|
|
```
|
|
|
|
|
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
# As YAML Configuration File
|
|
|
|
http:
|
|
|
|
routers:
|
|
|
|
router1:
|
2021-12-17 15:24:06 +00:00
|
|
|
service: service1
|
2021-06-11 13:30:05 +00:00
|
|
|
middlewares:
|
|
|
|
- "foo-add-prefix"
|
|
|
|
rule: "Host(`example.com`)"
|
|
|
|
|
|
|
|
middlewares:
|
|
|
|
foo-add-prefix:
|
|
|
|
addPrefix:
|
|
|
|
prefix: "/foo"
|
|
|
|
|
|
|
|
services:
|
|
|
|
service1:
|
|
|
|
loadBalancer:
|
|
|
|
servers:
|
|
|
|
- url: "http://127.0.0.1:80"
|
|
|
|
```
|
|
|
|
|
|
|
|
## Available HTTP Middlewares
|
|
|
|
|
|
|
|
| Middleware | Purpose | Area |
|
|
|
|
|-------------------------------------------|---------------------------------------------------|-----------------------------|
|
2021-08-19 13:00:11 +00:00
|
|
|
| [AddPrefix](addprefix.md) | Adds a Path Prefix | Path Modifier |
|
|
|
|
| [BasicAuth](basicauth.md) | Adds Basic Authentication | Security, Authentication |
|
2021-06-11 13:30:05 +00:00
|
|
|
| [Buffering](buffering.md) | Buffers the request/response | Request Lifecycle |
|
2021-08-19 13:00:11 +00:00
|
|
|
| [Chain](chain.md) | Combines multiple pieces of middleware | Misc |
|
|
|
|
| [CircuitBreaker](circuitbreaker.md) | Prevents calling unhealthy services | Request Lifecycle |
|
|
|
|
| [Compress](compress.md) | Compresses the response | Content Modifier |
|
|
|
|
| [ContentType](contenttype.md) | Handles Content-Type auto-detection | Misc |
|
2021-06-11 13:30:05 +00:00
|
|
|
| [DigestAuth](digestauth.md) | Adds Digest Authentication | Security, Authentication |
|
2021-08-19 13:00:11 +00:00
|
|
|
| [Errors](errorpages.md) | Defines custom error pages | Request Lifecycle |
|
|
|
|
| [ForwardAuth](forwardauth.md) | Delegates Authentication | Security, Authentication |
|
|
|
|
| [Headers](headers.md) | Adds / Updates headers | Security |
|
2022-10-26 15:16:05 +00:00
|
|
|
| [IPAllowList](ipallowlist.md) | Limits the allowed client IPs | Security, Request lifecycle |
|
2021-08-19 13:00:11 +00:00
|
|
|
| [InFlightReq](inflightreq.md) | Limits the number of simultaneous connections | Security, Request lifecycle |
|
|
|
|
| [PassTLSClientCert](passtlsclientcert.md) | Adds Client Certificates in a Header | Security |
|
|
|
|
| [RateLimit](ratelimit.md) | Limits the call frequency | Security, Request lifecycle |
|
|
|
|
| [RedirectScheme](redirectscheme.md) | Redirects based on scheme | Request lifecycle |
|
|
|
|
| [RedirectRegex](redirectregex.md) | Redirects based on regex | Request lifecycle |
|
|
|
|
| [ReplacePath](replacepath.md) | Changes the path of the request | Path Modifier |
|
|
|
|
| [ReplacePathRegex](replacepathregex.md) | Changes the path of the request | Path Modifier |
|
|
|
|
| [Retry](retry.md) | Automatically retries in case of error | Request lifecycle |
|
|
|
|
| [StripPrefix](stripprefix.md) | Changes the path of the request | Path Modifier |
|
|
|
|
| [StripPrefixRegex](stripprefixregex.md) | Changes the path of the request | Path Modifier |
|
2022-06-29 09:04:09 +00:00
|
|
|
|
|
|
|
## Community Middlewares
|
|
|
|
|
2022-09-14 08:56:08 +00:00
|
|
|
Please take a look at the community-contributed plugins in the [plugin catalog](https://plugins.traefik.io/plugins).
|
2022-09-09 15:17:53 +00:00
|
|
|
|
|
|
|
{!traefik-for-business-applications.md!}
|