Add routes priorities in documentation
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
cc4fb64b34
commit
7e6c580130
3 changed files with 42 additions and 15 deletions
|
@ -84,6 +84,7 @@ Here is an example of frontends definition:
|
||||||
[frontends.frontend2]
|
[frontends.frontend2]
|
||||||
backend = "backend1"
|
backend = "backend1"
|
||||||
passHostHeader = true
|
passHostHeader = true
|
||||||
|
priority = 10
|
||||||
entrypoints = ["https"] # overrides defaultEntryPoints
|
entrypoints = ["https"] # overrides defaultEntryPoints
|
||||||
[frontends.frontend2.routes.test_1]
|
[frontends.frontend2.routes.test_1]
|
||||||
rule = "Host: localhost, {subdomain:[a-z]+}.localhost"
|
rule = "Host: localhost, {subdomain:[a-z]+}.localhost"
|
||||||
|
@ -97,6 +98,27 @@ Here is an example of frontends definition:
|
||||||
- `frontend2` will forward the traffic to the `backend1` if the rule `Host: localhost, {subdomain:[a-z]+}.localhost` is matched (forwarding client `Host` header to the backend)
|
- `frontend2` will forward the traffic to the `backend1` if the rule `Host: localhost, {subdomain:[a-z]+}.localhost` is matched (forwarding client `Host` header to the backend)
|
||||||
- `frontend3` will forward the traffic to the `backend2` if the rules `Host: test3.localhost` and `Path:/test` are matched
|
- `frontend3` will forward the traffic to the `backend2` if the rules `Host: test3.localhost` and `Path:/test` are matched
|
||||||
|
|
||||||
|
By default, routes will be sorted using rules length (to avoid path overlap):
|
||||||
|
`PathPrefix:/12345` will be matched before `PathPrefix:/1234` that will be matched before `PathPrefix:/1`.
|
||||||
|
|
||||||
|
You can customize priority by frontend:
|
||||||
|
|
||||||
|
```
|
||||||
|
[frontends]
|
||||||
|
[frontends.frontend1]
|
||||||
|
backend = "backend1"
|
||||||
|
priority = 10
|
||||||
|
passHostHeader = true
|
||||||
|
[frontends.frontend1.routes.test_1]
|
||||||
|
rule = "PathPrefix:/to"
|
||||||
|
[frontends.frontend2]
|
||||||
|
priority = 5
|
||||||
|
backend = "backend2"
|
||||||
|
passHostHeader = true
|
||||||
|
[frontends.frontend2.routes.test_1]
|
||||||
|
rule = "PathPrefix:/toto"
|
||||||
|
```
|
||||||
|
|
||||||
## Backends
|
## Backends
|
||||||
|
|
||||||
A backend is responsible to load-balance the traffic coming from one or more frontends to a set of http servers.
|
A backend is responsible to load-balance the traffic coming from one or more frontends to a set of http servers.
|
||||||
|
|
24
docs/toml.md
24
docs/toml.md
|
@ -301,6 +301,7 @@ defaultEntryPoints = ["http", "https"]
|
||||||
[frontends.frontend2]
|
[frontends.frontend2]
|
||||||
backend = "backend1"
|
backend = "backend1"
|
||||||
passHostHeader = true
|
passHostHeader = true
|
||||||
|
priority = 10
|
||||||
entrypoints = ["https"] # overrides defaultEntryPoints
|
entrypoints = ["https"] # overrides defaultEntryPoints
|
||||||
[frontends.frontend2.routes.test_1]
|
[frontends.frontend2.routes.test_1]
|
||||||
rule = "Host:{subdomain:[a-z]+}.localhost"
|
rule = "Host:{subdomain:[a-z]+}.localhost"
|
||||||
|
@ -367,6 +368,7 @@ filename = "rules.toml"
|
||||||
[frontends.frontend2]
|
[frontends.frontend2]
|
||||||
backend = "backend1"
|
backend = "backend1"
|
||||||
passHostHeader = true
|
passHostHeader = true
|
||||||
|
priority = 10
|
||||||
entrypoints = ["https"] # overrides defaultEntryPoints
|
entrypoints = ["https"] # overrides defaultEntryPoints
|
||||||
[frontends.frontend2.routes.test_1]
|
[frontends.frontend2.routes.test_1]
|
||||||
rule = "Host:{subdomain:[a-z]+}.localhost"
|
rule = "Host:{subdomain:[a-z]+}.localhost"
|
||||||
|
@ -583,6 +585,7 @@ Labels can be used on containers to override default behaviour:
|
||||||
- `traefik.enable=false`: disable this container in Træfɪk
|
- `traefik.enable=false`: disable this container in Træfɪk
|
||||||
- `traefik.frontend.rule=Host:test.traefik.io`: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
|
- `traefik.frontend.rule=Host:test.traefik.io`: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
|
||||||
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend.
|
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend.
|
||||||
|
- `traefik.frontend.priority=10`: override default frontend priority
|
||||||
- `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`.
|
- `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`.
|
||||||
- `traefik.domain=traefik.localhost`: override the default domain
|
- `traefik.domain=traefik.localhost`: override the default domain
|
||||||
- `traefik.docker.network`: Set the docker network to use for connections to this container
|
- `traefik.docker.network`: Set the docker network to use for connections to this container
|
||||||
|
@ -673,6 +676,7 @@ Labels can be used on containers to override default behaviour:
|
||||||
- `traefik.enable=false`: disable this application in Træfɪk
|
- `traefik.enable=false`: disable this application in Træfɪk
|
||||||
- `traefik.frontend.rule=Host:test.traefik.io`: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
|
- `traefik.frontend.rule=Host:test.traefik.io`: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
|
||||||
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend.
|
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend.
|
||||||
|
- `traefik.frontend.priority=10`: override default frontend priority
|
||||||
- `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`.
|
- `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`.
|
||||||
- `traefik.domain=traefik.localhost`: override the default domain
|
- `traefik.domain=traefik.localhost`: override the default domain
|
||||||
|
|
||||||
|
@ -810,14 +814,15 @@ used in consul.
|
||||||
|
|
||||||
Additional settings can be defined using Consul Catalog tags:
|
Additional settings can be defined using Consul Catalog tags:
|
||||||
|
|
||||||
- ```traefik.enable=false```: disable this container in Træfɪk
|
- `traefik.enable=false`: disable this container in Træfɪk
|
||||||
- ```traefik.protocol=https```: override the default `http` protocol
|
- `traefik.protocol=https`: override the default `http` protocol
|
||||||
- ```traefik.backend.weight=10```: assign this weight to the container
|
- `traefik.backend.weight=10`: assign this weight to the container
|
||||||
- ```traefik.backend.circuitbreaker=NetworkErrorRatio() > 0.5```
|
- `traefik.backend.circuitbreaker=NetworkErrorRatio() > 0.5`
|
||||||
- ```traefik.backend.loadbalancer=drr```: override the default load balancing mode
|
- `traefik.backend.loadbalancer=drr`: override the default load balancing mode
|
||||||
- ```traefik.frontend.rule=Host:test.traefik.io```: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
|
- `traefik.frontend.rule=Host:test.traefik.io`: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
|
||||||
- ```traefik.frontend.passHostHeader=true```: forward client `Host` header to the backend.
|
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend.
|
||||||
- ```traefik.frontend.entryPoints=http,https```: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`.
|
- `traefik.frontend.priority=10`: override default frontend priority
|
||||||
|
- `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`.
|
||||||
|
|
||||||
## Etcd backend
|
## Etcd backend
|
||||||
|
|
||||||
|
@ -992,9 +997,10 @@ The Keys-Values structure should look (using `prefix = "/traefik"`):
|
||||||
- frontend 2
|
- frontend 2
|
||||||
|
|
||||||
| Key | Value |
|
| Key | Value |
|
||||||
|----------------------------------------------------|--------------|
|
|----------------------------------------------------|--------------------|
|
||||||
| `/traefik/frontends/frontend2/backend` | `backend1` |
|
| `/traefik/frontends/frontend2/backend` | `backend1` |
|
||||||
| `/traefik/frontends/frontend2/passHostHeader` | `true` |
|
| `/traefik/frontends/frontend2/passHostHeader` | `true` |
|
||||||
|
| `/traefik/frontends/frontend2/priority` | `10` |
|
||||||
| `/traefik/frontends/frontend2/entrypoints` | `http,https` |
|
| `/traefik/frontends/frontend2/entrypoints` | `http,https` |
|
||||||
| `/traefik/frontends/frontend2/routes/test_2/rule` | `PathPrefix:/test` |
|
| `/traefik/frontends/frontend2/routes/test_2/rule` | `PathPrefix:/test` |
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"github.com/containous/mux"
|
"github.com/containous/mux"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,7 +53,6 @@ func TestParseTwoRules(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestPriorites(t *testing.T) {
|
func TestPriorites(t *testing.T) {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.StrictSlash(true)
|
router.StrictSlash(true)
|
||||||
|
@ -130,4 +130,3 @@ type fakeHandler struct {
|
||||||
func (h *fakeHandler) ServeHTTP(http.ResponseWriter, *http.Request) {
|
func (h *fakeHandler) ServeHTTP(http.ResponseWriter, *http.Request) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue