# 入口定义
[entryPoints]
[entryPoints.http]
address = ":80"
# 强制跳转到 https
[entryPoints.http.redirect]
entryPoint = "https"
# url 重写
[entryPoints.http.redirect]
regex = "^http://localhost/(.*)"
replacement = "http://mydomain/$1"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
clientCAFiles = ["tests/clientca1.crt", "tests/clientca2.crt"]
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "tests/traefik.crt"
keyFile = "tests/traefik.key"
# 前端
[frontends]
# 定义一个前端
[frontends.frontend1]
# 指定后端
backend = "backend2"
# 定义路由规则
[frontends.frontend1.routes.test_1]
rule = "Host:test.localhost,test2.localhost"
# 可以使用自定义头
[frontends.frontend1.headers.customresponseheaders]
X-Custom-Response-Header = "True"
[frontends.frontend1.headers.customrequestheaders]
X-Script-Name = "test"
# 定义了一个前端
[frontends.frontend2]
# 均直接转发
backend = "backend1"
passHostHeader = true
passTLSCert = true
# 指定优先级
priority = 10
entrypoints = ["https"] # overrides defaultEntryPoints
[frontends.frontend2.routes.test_1]
rule = "HostRegexp:localhost,{subdomain:[a-z]+}.localhost"
[frontends.frontend3]
backend = "backend2"
# 规则可以写在一起也可以分开写
[frontends.frontend3.routes.test_1]
rule = "Host:test3.localhost;Path:/test"
[frontends.frontend3.routes.test_2]
rule = "Query: test=1"
# 后端
[backends]
[backends.backend1]
# 定义熔断机制
[backends.backend1.circuitbreaker]
expression = "NetworkErrorRatio() > 0.5"
# 设置最大连接数
[backends.backend1.maxconn]
amount = 10
extractorfunc = "request.host"
# 定义后端服务
[backends.backend1.servers.server1]
url = "http://172.17.0.2:80"
weight = 10
[backends.backend1.servers.server2]
url = "http://172.17.0.3:80"
weight = 1
# 定义健康检查
[backends.backend1.healthcheck]
path = "/health"
interval = "10s"
port = 8080
[backends.backend2]
# 设置负载方式
[backends.backend2.LoadBalancer]
method = "drr"
[backends.backend2.loadbalancer.stickiness]
# 定义粘性会话
# 可选, 默认为 sha1 六位字符
cookieName = "my_cookie"
[backends.backend2.servers.server1]
url = "http://172.17.0.4:80"
weight = 1
[backends.backend2.servers.server2]
url = "http://172.17.0.5:80"
weight = 2