2019-02-26 13:50:07 +00:00
|
|
|
# Chain
|
|
|
|
|
|
|
|
When One Isn't Enougth
|
|
|
|
{: .subtitle }
|
|
|
|
|
|
|
|
![Chain](../assets/img/middleware/chain.png)
|
|
|
|
|
|
|
|
The Chain middleware enables you to define reusable combinations of other pieces of middleware.
|
|
|
|
It makes reusing the same groups easier.
|
|
|
|
|
|
|
|
## Configuration Example
|
|
|
|
|
|
|
|
??? example "A Chain for WhiteList, BasicAuth, and HTTPS"
|
|
|
|
|
|
|
|
```toml
|
|
|
|
# ...
|
2019-03-14 08:30:04 +00:00
|
|
|
[http.routers]
|
|
|
|
[http.routers.router1]
|
2019-02-26 13:50:07 +00:00
|
|
|
service = "service1"
|
|
|
|
middlewares = ["secured"]
|
|
|
|
rule = "Host: mydomain"
|
|
|
|
|
2019-03-14 08:30:04 +00:00
|
|
|
[http.middlewares]
|
|
|
|
[http.middlewares.secured.Chain]
|
2019-02-26 13:50:07 +00:00
|
|
|
middlewares = ["https-only", "known-ips", "auth-users"]
|
|
|
|
|
2019-03-14 08:30:04 +00:00
|
|
|
[http.middlewares.auth-users.BasicAuth]
|
2019-02-26 13:50:07 +00:00
|
|
|
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"]
|
2019-03-14 08:30:04 +00:00
|
|
|
[http.middlewares.https-only.SchemeRedirect]
|
2019-02-26 13:50:07 +00:00
|
|
|
scheme = "https"
|
2019-03-14 08:30:04 +00:00
|
|
|
[http.middlewares.known-ips.ipWhiteList]
|
2019-02-26 13:50:07 +00:00
|
|
|
sourceRange = ["192.168.1.7", "x.x.x.x", "x.x.x.x"]
|
|
|
|
|
2019-03-14 08:30:04 +00:00
|
|
|
[http.services]
|
|
|
|
[http.services.service1]
|
|
|
|
[http.services.service1.LoadBalancer]
|
|
|
|
[[http.services.service1.LoadBalancer.Servers]]
|
2019-02-26 13:50:07 +00:00
|
|
|
URL = "http://127.0.0.1:80"
|
|
|
|
Weight = 1
|
|
|
|
```
|