Enhance middleware examples.

This commit is contained in:
Ludovic Fernandez 2019-03-29 12:34:05 +01:00 committed by Traefiker Bot
parent fa2c57f7cb
commit a45f285a5c
15 changed files with 286 additions and 345 deletions

View file

@ -9,34 +9,28 @@ The AddPrefix middleware updates the URL Path of the request before forwarding i
## Configuration Examples ## Configuration Examples
??? example "File -- Prefixing with /foo" ```yaml tab="Docker"
# Prefixing with /foo
labels:
- "traefik.http.middlewares.add-bar.addprefix.prefix=/foo"
```
```toml ```yaml tab="Kubernetes"
[http.middlewares] apiVersion: traefik.containo.us/v1alpha1
[http.middlewares.add-foo.AddPrefix] kind: Middleware
prefix = "/foo" metadata:
```
??? example "Docker -- Prefixing with /bar"
```yaml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.add-bar.addprefix.prefix=/bar"
```
??? example "Kubernetes -- Prefixing with /bar"
```yaml
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: addprefix name: addprefix
spec: spec:
addprefix: addprefix:
prefix: /bar prefix: /bar
``` ```
```toml tab="File"
# Prefixing with /foo
[http.middlewares]
[http.middlewares.add-foo.AddPrefix]
prefix = "/foo"
```
## Configuration Options ## Configuration Options

View file

@ -9,23 +9,19 @@ The BasicAuth middleware is a quick way to restrict access to your services to k
## Configuration Examples ## Configuration Examples
??? example "File -- Declaring the user list" ```yaml tab="Docker"
# Declaring the user list
labels:
- "traefik.http.middlewares.declared-users-only.basicauth.users=test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
```
```toml ```toml tab="File"
[http.middlewares] # Declaring the user list
[http.middlewares]
[http.middlewares.test-auth.basicauth] [http.middlewares.test-auth.basicauth]
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
"test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"] "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
``` ```
??? example "Docker -- Using an external file for the authorized users"
```yml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.declared-users-only.basicauth.usersFile=path-to-file.ext",
```
## Configuration Options ## Configuration Options

View file

@ -13,22 +13,18 @@ This can help services deal with large data (multipart/form-data for example), a
## Configuration Examples ## Configuration Examples
??? example "File -- Sets the maximum request body to 2Mb" ```yaml tab="Docker"
# Sets the maximum request body to 2Mb
labels:
- "traefik.http.middlewares.2Mb-memory.buffering.maxRequestBodyBytes=250000",
```
```toml ```toml tab="File"
[http.middlewares] # Sets the maximum request body to 2Mb
[http.middlewares]
[http.middlewares.2Mb-limit.buffering] [http.middlewares.2Mb-limit.buffering]
maxRequestBodyBytes = 250000 maxRequestBodyBytes = 250000
``` ```
??? example "Docker -- Buffers 1Mb of the request in memory, then writes to disk"
```yaml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.1Mb-memory.buffering.memRequestBodyBytes=125000",
```
## Configuration Options ## Configuration Options

View file

@ -23,23 +23,18 @@ To assess if your system is healthy, the circuit breaker constantly monitors the
## Configuration Examples ## Configuration Examples
??? example "Latency Check -- Using Toml" ```yaml tab="Docker"
# Latency Check
labels:
- "traefik.http.middlewares.latency-check.circuitbreaker.expression=LatencyAtQuantileMS(50.0) > 100"
```
```toml ```toml tab="File"
[http.middlewares] # Latency Check
[http.middlewares]
[http.middlewares.latency-check.circuitbreaker] [http.middlewares.latency-check.circuitbreaker]
expression = "LatencyAtQuantileMS(50.0) > 100" expression = "LatencyAtQuantileMS(50.0) > 100"
``` ```
??? example "Latency Check -- Using Docker Labels"
```yaml
# in a docker compose file
container-definition:
image: image-name
labels:
- "traefik.http.middlewares.latency-check.circuitbreaker.expression=LatencyAtQuantileMS(50.0) > 100"
```
## Possible States ## Possible States

View file

@ -9,21 +9,17 @@ The Compress middleware enables the gzip compression.
## Configuration Examples ## Configuration Examples
??? example "File -- enable gzip compression" ```yaml tab="Docker"
# Enable gzip compression
labels:
- "traefik.http.middlewares.test-compress.compress=true",
```
```toml ```toml tab="File"
[http.middlewares] # Enable gzip compression
[http.middlewares]
[http.middlewares.test-compress.Compress] [http.middlewares.test-compress.Compress]
``` ```
??? example "Docker -- enable gzip compression"
```yml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.test-compress.compress=true",
```
## Notes ## Notes

View file

@ -9,23 +9,17 @@ The DigestAuth middleware is a quick way to restrict access to your services to
## Configuration Examples ## Configuration Examples
??? example "File -- Declaring the user list" ```yaml tab="Docker"
labels:
- "traefik.http.middlewares.declared-users-only.digestauth.usersFile=path-to-file.ext",
```
```toml ```toml tab="File"
[http.middlewares] [http.middlewares]
[http.middlewares.test-auth.digestauth] [http.middlewares.test-auth.digestauth]
users = ["test:traefik:a2688e031edb4be6a3797f3882655c05", users = ["test:traefik:a2688e031edb4be6a3797f3882655c05",
"test2:traefik:518845800f9e2bfb1f1f740ec24f074e"] "test2:traefik:518845800f9e2bfb1f1f740ec24f074e"]
``` ```
??? example "Docker -- Using an external file for the authorized users"
```yml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.declared-users-only.digestauth.usersFile=path-to-file.ext",
```
!!! tip !!! tip

View file

@ -12,37 +12,32 @@ The ErrorPage middleware returns a custom page in lieu of the default, according
## Configuration Examples ## Configuration Examples
??? example "File -- Custom Error Page for 5XX" ```yaml tab="Docker"
# Dynamic Custom Error Page for 5XX Status Code
labels:
- "traefik.http.middlewares.test-errorpage.errors.status=500-599",
- "traefik.http.middlewares.test-errorpage.errors.service=serviceError",
- "traefik.http.middlewares.test-errorpage.errors.query=/{status}.html",
```
```toml ```toml tab="File"
[http.routers] # Custom Error Page for 5XX
[http.routers]
[http.routers.router1] [http.routers.router1]
Service = "my-service" Service = "my-service"
Rule = Host(`my-domain`) Rule = Host(`my-domain`)
[http.middlewares] [http.middlewares]
[http.middlewares.5XX-errors.Errors] [http.middlewares.5XX-errors.Errors]
status = ["500-599"] status = ["500-599"]
service = "error-handler-service" service = "error-handler-service"
query = "/error.html" query = "/error.html"
[http.services] [http.services]
# ... definition of error-handler-service and my-service # ... definition of error-handler-service and my-service
``` ```
??? example "Docker -- Dynamic Custom Error Page for 5XX Status Code" !!! note
```yaml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.test-errorpage.errors.status=500-599",
- "traefik.http.middlewares.test-errorpage.errors.service=serviceError",
- "traefik.http.middlewares.test-errorpage.errors.query=/{status}.html",
```
!!! note
In this example, the error page URL is based on the status code (`query=/{status}.html)`. In this example, the error page URL is based on the status code (`query=/{status}.html)`.
## Configuration Options ## Configuration Options

View file

@ -11,10 +11,9 @@ Otherwise, the response from the authentication server is returned.
## Configuration Examples ## Configuration Examples
??? example "File -- Forward authentication to authserver.com" ```toml tab="File"
# Forward authentication to authserver.com
```toml [http.middlewares]
[http.middlewares]
[http.middlewares.test-auth.forwardauth] [http.middlewares.test-auth.forwardauth]
address = "https://authserver.com/auth" address = "https://authserver.com/auth"
trustForwardHeader = true trustForwardHeader = true
@ -25,24 +24,20 @@ Otherwise, the response from the authentication server is returned.
caOptional = true caOptional = true
cert = "path/to/foo.cert" cert = "path/to/foo.cert"
key = "path/to/foo.key" key = "path/to/foo.key"
``` ```
??? example "Docker -- Forward authentication to authserver.com" ```yaml tab="Docker"
# Forward authentication to authserver.com
```yml labels:
a-container: - "traefik.http.middlewares.test-auth.ForwardAuth.Address=https://authserver.com/auth"
image: a-container-image - "traefik.http.middlewares.test-auth.ForwardAuth.AuthResponseHeaders=X-Auth-User, X-Secret"
labels: - "traefik.http.middlewares.test-auth.ForwardAuth.TLS.CA=path/to/local.crt"
- "traefik.http.middlewares.test-auth.ForwardAuth.Address=https://authserver.com/auth" - "traefik.http.middlewares.test-auth.ForwardAuth.TLS.CAOptional=true"
- "traefik.http.middlewares.test-auth.ForwardAuth.AuthResponseHeaders=X-Auth-User, X-Secret" - "traefik.http.middlewares.test-auth.ForwardAuth.TLS.Cert=path/to/foo.cert"
- "traefik.http.middlewares.test-auth.ForwardAuth.TLS.CA=path/to/local.crt" - "traefik.http.middlewares.test-auth.ForwardAuth.TLS.InsecureSkipVerify=true"
- "traefik.http.middlewares.test-auth.ForwardAuth.TLS.CAOptional=true" - "traefik.http.middlewares.test-auth.ForwardAuth.TLS.Key=path/to/foo.key"
- "traefik.http.middlewares.test-auth.ForwardAuth.TLS.Cert=path/to/foo.cert" - "traefik.http.middlewares.test-auth.ForwardAuth.TrustForwardHeader=true"
- "traefik.http.middlewares.test-auth.ForwardAuth.TLS.InsecureSkipVerify=true" ```
- "traefik.http.middlewares.test-auth.ForwardAuth.TLS.Key=path/to/foo.key"
- "traefik.http.middlewares.test-auth.ForwardAuth.TrustForwardHeader=true"
```
## Configuration Options ## Configuration Options

View file

@ -13,26 +13,22 @@ The Headers middleware can manage the requests/responses headers.
Add the `X-Script-Name` header to the proxied request and the `X-Custom-Response-Header` to the response Add the `X-Script-Name` header to the proxied request and the `X-Custom-Response-Header` to the response
??? example "File" ```yaml tab="Docker"
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.testHeader.Headers.CustomRequestHeaders.X-Script-Name=test",
- "traefik.http.middlewares.testHeader.Headers.CustomResponseHeaders.X-Custom-Response-Header=True",
```
```toml ```toml tab="File"
[http.middlewares] [http.middlewares]
[http.middlewares.testHeader.headers] [http.middlewares.testHeader.headers]
[http.middlewares.testHeader.headers.CustomRequestHeaders] [http.middlewares.testHeader.headers.CustomRequestHeaders]
X-Script-Name = "test" X-Script-Name = "test"
[http.middlewares.testHeader.headers.CustomResponseHeaders] [http.middlewares.testHeader.headers.CustomResponseHeaders]
X-Custom-Response-Header = "True" X-Custom-Response-Header = "True"
``` ```
??? example "Docker"
```yml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.testHeader.Headers.CustomRequestHeaders.X-Script-Name=test",
- "traefik.http.middlewares.testHeader.Headers.CustomResponseHeaders.X-Custom-Response-Header=True",
```
### Adding and Removing Headers ### Adding and Removing Headers

View file

@ -9,22 +9,18 @@ IPWhitelist accepts / refuses requests based on the client IP.
## Configuration Examples ## Configuration Examples
??? example "File -- Accepts request from defined IP" ```yaml tab="Docker"
# Accepts request from defined IP
labels:
- "traefik.http.middlewares.Middleware9.IPWhiteList.SourceRange=127.0.0.1/32, 192.168.1.7"
```
```toml ```toml tab="File"
[http.middlewares] # Accepts request from defined IP
[http.middlewares]
[http.middlewares.test-ipwhitelist.ipWhiteList] [http.middlewares.test-ipwhitelist.ipWhiteList]
sourceRange = ["127.0.0.1/32", "192.168.1.7"] sourceRange = ["127.0.0.1/32", "192.168.1.7"]
``` ```
??? example "Docker -- Accepts request from defined IP"
```yml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.Middleware9.IPWhiteList.SourceRange=127.0.0.1/32, 192.168.1.7"
```
## Configuration Options ## Configuration Options

View file

@ -9,22 +9,18 @@ To proactively prevent services from being overwhelmed with high load, a maximum
## Configuration Examples ## Configuration Examples
??? example "File -- Limiting to 10 simultaneous connections" ```yaml tab="Docker"
# Limiting to 10 simultaneous connections
labels:
- "traefik.http.middlewares.test-maxconn.maxconn.amount=10"
```
```toml ```toml tab="File"
[http.middlewares] # Limiting to 10 simultaneous connections
[http.middlewares]
[http.middlewares.test-maxconn.maxconn] [http.middlewares.test-maxconn.maxconn]
amount = 10 amount = 10
``` ```
??? example "Docker -- Limiting to 10 simultaneous connections"
```yml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.test-maxconn.maxconn.amount=10"
```
## Configuration Options ## Configuration Options

View file

@ -13,49 +13,21 @@ Pieces of middleware can be combined in chains to fit every scenario.
## Configuration Example ## Configuration Example
??? example "As Toml Configuration File" ```yaml tab="Docker"
# As a Docker Label
```toml whoami:
[providers]
[providers.file]
[http.routers]
[http.routers.router1]
Service = "myService"
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"
Weight = 1
```
??? example "As a Docker Label"
```yaml
# A container that exposes a simple API
whoami:
image: containous/whoami # A container that exposes an API to show its IP address image: containous/whoami # A container that exposes an API to show its IP address
labels: labels:
- "traefik.http.middlewares.foo-add-prefix.addprefix.prefix=/foo", - "traefik.http.middlewares.foo-add-prefix.addprefix.prefix=/foo",
``` ```
??? example "As a Kubernetes Traefik IngressRoute" ```yaml tab="Kubernetes"
# As a Kubernetes Traefik IngressRoute
```yaml apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition
kind: CustomResourceDefinition metadata:
metadata:
name: middlewares.traefik.containo.us name: middlewares.traefik.containo.us
spec: spec:
group: traefik.containo.us group: traefik.containo.us
version: v1alpha1 version: v1alpha1
names: names:
@ -64,28 +36,52 @@ Pieces of middleware can be combined in chains to fit every scenario.
singular: middleware singular: middleware
scope: Namespaced scope: Namespaced
--- ---
apiVersion: traefik.containo.us/v1alpha1 apiVersion: traefik.containo.us/v1alpha1
kind: Middleware kind: Middleware
metadata: metadata:
name: stripprefix name: stripprefix
spec: spec:
stripprefix: stripprefix:
prefixes: prefixes:
- /stripit - /stripit
--- ---
apiVersion: traefik.containo.us/v1alpha1 apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute kind: IngressRoute
metadata: metadata:
name: ingressroute.crd name: ingressroute.crd
spec: spec:
# more fields... # more fields...
routes: routes:
# more fields... # more fields...
middleware: middleware:
- name: stripprefix - name: stripprefix
``` ```
```toml tab="File"
# As Toml Configuration File
[providers]
[providers.file]
[http.routers]
[http.routers.router1]
Service = "myService"
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"
Weight = 1
```
## Advanced Configuration ## Advanced Configuration

View file

@ -9,26 +9,47 @@ PassTLSClientCert adds in header the selected data from the passed client tls ce
## Configuration Examples ## Configuration Examples
??? example "File -- Pass the escaped pem in the `X-Forwarded-Tls-Client-Cert` header" Pass the escaped pem in the `X-Forwarded-Tls-Client-Cert` header.
```toml ```yaml tab="Docker"
[http.middlewares] # Pass the escaped pem in the `X-Forwarded-Tls-Client-Cert` header.
labels:
- "traefik.http.middlewares.Middleware11.passtlsclientcert.pem=true"
```
```toml tab="File"
# Pass the escaped pem in the `X-Forwarded-Tls-Client-Cert` header.
[http.middlewares]
[http.middlewares.test-passtlsclientcert.passtlsclientcert] [http.middlewares.test-passtlsclientcert.passtlsclientcert]
pem = true pem = true
``` ```
??? example "Docker -- Pass the escaped pem in the `X-Forwarded-Tls-Client-Cert` header" ??? example "Pass the escaped pem in the `X-Forwarded-Tls-Client-Cert` header"
```yml ```yaml tab="Docker"
a-container: # Pass all the available info in the `X-Forwarded-Tls-Client-Cert-Info` header
image: a-container-image
labels: labels:
- "traefik.http.middlewares.Middleware11.passtlsclientcert.pem=true" - "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.notafter=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.notbefore=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.sans=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.commonname=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.country=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.domaincomponent=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.locality=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.organization=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.province=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.serialnumber=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.commonname=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.country=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.domaincomponent=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.locality=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.organization=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.province=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.serialnumber=true"
``` ```
??? example "File -- Pass all the available info in the `X-Forwarded-Tls-Client-Cert-Info` header" ```toml tab="File"
# Pass all the available info in the `X-Forwarded-Tls-Client-Cert-Info` header
```toml
[http.middlewares] [http.middlewares]
[http.middlewares.test-passtlsclientcert.passtlsclientcert] [http.middlewares.test-passtlsclientcert.passtlsclientcert]
[http.middlewares.test-passtlsclientcert.passtlsclientcert.info] [http.middlewares.test-passtlsclientcert.passtlsclientcert.info]
@ -53,31 +74,6 @@ PassTLSClientCert adds in header the selected data from the passed client tls ce
domainComponent = true domainComponent = true
``` ```
??? example "Docker -- Pass all the available info in the `X-Forwarded-Tls-Client-Cert-Info` header"
```yml
a-container:
image: a-container-image
labels:
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.notafter=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.notbefore=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.sans=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.commonname=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.country=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.domaincomponent=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.locality=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.organization=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.province=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.subject.serialnumber=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.commonname=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.country=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.domaincomponent=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.locality=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.organization=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.province=true"
- "traefik.http.middlewares.test-passtlsclientcert.passtlsclientcert.info.issuer.serialnumber=true"
```
## Configuration Options ## Configuration Options
### General ### General

View file

@ -1,5 +1,5 @@
mkdocs==1.0.4 mkdocs==1.0.4
pymdown-extensions==6.0 pymdown-extensions==6.0
mkdocs-bootswatch==1.0 mkdocs-bootswatch==1.0
mkdocs-material==3.3.0 mkdocs-material==4.0.2
markdown-include==0.5.1 markdown-include==0.5.1