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,26 +9,13 @@ 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
```toml
[http.middlewares]
[http.middlewares.add-foo.AddPrefix]
prefix = "/foo"
```
??? example "Docker -- Prefixing with /bar"
```yaml
a-container:
image: a-container-image
labels: labels:
- "traefik.http.middlewares.add-bar.addprefix.prefix=/bar" - "traefik.http.middlewares.add-bar.addprefix.prefix=/foo"
``` ```
??? example "Kubernetes -- Prefixing with /bar" ```yaml tab="Kubernetes"
```yaml
apiVersion: traefik.containo.us/v1alpha1 apiVersion: traefik.containo.us/v1alpha1
kind: Middleware kind: Middleware
metadata: metadata:
@ -38,6 +25,13 @@ The AddPrefix middleware updates the URL Path of the request before forwarding i
prefix: /bar prefix: /bar
``` ```
```toml tab="File"
# Prefixing with /foo
[http.middlewares]
[http.middlewares.add-foo.AddPrefix]
prefix = "/foo"
```
## Configuration Options ## Configuration Options
### prefix ### prefix

View file

@ -9,24 +9,20 @@ 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"
# Declaring the user list
[http.middlewares] [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
### General ### General

View file

@ -13,23 +13,19 @@ 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"
# Sets the maximum request body to 2Mb
[http.middlewares] [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
### maxRequestBodyBytes ### maxRequestBodyBytes

View file

@ -23,24 +23,19 @@ 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"
# Latency Check
[http.middlewares] [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
There are three possible states for your circuit breaker: There are three possible states for your circuit breaker:

View file

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

View file

@ -9,24 +9,18 @@ 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
Use `htdigest` to generate passwords. Use `htdigest` to generate passwords.

View file

@ -12,9 +12,16 @@ 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"
# Custom Error Page for 5XX
[http.routers] [http.routers]
[http.routers.router1] [http.routers.router1]
Service = "my-service" Service = "my-service"
@ -30,18 +37,6 @@ The ErrorPage middleware returns a custom page in lieu of the default, according
# ... 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"
```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 !!! 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)`.

View file

@ -11,9 +11,8 @@ 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"
@ -27,11 +26,8 @@ Otherwise, the response from the authentication server is returned.
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
a-container:
image: a-container-image
labels: labels:
- "traefik.http.middlewares.test-auth.ForwardAuth.Address=https://authserver.com/auth" - "traefik.http.middlewares.test-auth.ForwardAuth.Address=https://authserver.com/auth"
- "traefik.http.middlewares.test-auth.ForwardAuth.AuthResponseHeaders=X-Auth-User, X-Secret" - "traefik.http.middlewares.test-auth.ForwardAuth.AuthResponseHeaders=X-Auth-User, X-Secret"
@ -41,7 +37,6 @@ Otherwise, the response from the authentication server is returned.
- "traefik.http.middlewares.test-auth.ForwardAuth.TLS.InsecureSkipVerify=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.TLS.Key=path/to/foo.key"
- "traefik.http.middlewares.test-auth.ForwardAuth.TrustForwardHeader=true" - "traefik.http.middlewares.test-auth.ForwardAuth.TrustForwardHeader=true"
``` ```
## Configuration Options ## Configuration Options

View file

@ -13,9 +13,15 @@ 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]
@ -24,16 +30,6 @@ Add the `X-Script-Name` header to the proxied request and the `X-Custom-Response
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
`X-Script-Name` header added to the proxied request, the `X-Custom-Request-Header` header removed from the request, and the `X-Custom-Response-Header` header removed from the response. `X-Script-Name` header added to the proxied request, the `X-Custom-Request-Header` header removed from the request, and the `X-Custom-Response-Header` header removed from the response.

View file

@ -9,23 +9,19 @@ 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"
# Accepts request from defined IP
[http.middlewares] [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
### sourceRange ### sourceRange

View file

@ -9,23 +9,19 @@ 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"
# Limiting to 10 simultaneous connections
[http.middlewares] [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
### amount ### amount

View file

@ -13,44 +13,16 @@ 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
[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: 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:
@ -87,6 +59,30 @@ Pieces of middleware can be combined in chains to fit every scenario.
- 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
When you declare a middleware, it lives in its `provider` namespace. When you declare a middleware, it lives in its `provider` namespace.

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"
# 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]
[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