使用traefik 分配服务转发
配置两个文件
traefik.toml
[log]
level = "DEBUG"
filePath = "log-file.log"
[accessLog]
filePath = "log-access.log"
bufferingSize = 100
[providers]
[providers.file]
filename = "traefik-dynamic.toml"
[api]
dashboard = true
debug = true
[entryPoints]
[entryPoints.web]
address = ":31000"
[entryPoints.web-secure]
address = ":443"
[entryPoints.dashboard]
address = ":31080"
[certificatesResolvers.sample.acme]
email = "myemail@example.com"
storage = "acme.json"
[certificatesResolvers.sample.acme.httpChallenge]
# used during the challenge
entryPoint = "web"
traefik-dynamic.toml
[http]
# Redirect to https
[http.middlewares]
[http.middlewares.test-redirectscheme.redirectScheme]
scheme = "https"
[http.middlewares.test-auth.forwardAuth]
address = "http://localhost:9002/auth" //中间件配置 类型 forwardAuth 参考官方文档 https://doc.traefik.io/traefik/middlewares/http/forwardauth/
[http.routers]
[http.routers.router-1]
rule = "Host(`www.zhizhicloud.com`)"
service = "console"
entryPoints = ["web"]
[http.routers.router-2]
rule = "Host(`www.zhizhicloud.com`) && PathPrefix(`/front`)"
service = "front"
entryPoints = ["web"]
[http.routers.router-3]
rule = "Host(`traefik.spm.com`)"
service = "cdeserver"
entryPoints = ["web"]
middlewares=["test-auth"] //配置中间件。对应上边的中间件test-auth。。。。。。
[http.routers.router-4]
rule = "Host(`www.zhizhicloud.com`) && PathPrefix(`/iotlive`)"
service = "iotlive"
entryPoints = ["web"]
[http.routers.router-5]
rule = "Host(`www.zhizhicloud.com`) && PathPrefix(`/spm`)"
service = "spm"
entryPoints = ["web"]
[http.routers.router-6]
rule = "PathPrefix(`/auth`)"
service = "auth"
entryPoints = ["web"]
[http.routers.router-1.tls]
certResolver = "sample"
[http.services]
[http.services.console.loadbalancer]
[[http.services.console.loadbalancer.servers]]
url = "http://127.0.0.1:80"
[http.services.front.loadbalancer]
[[http.services.front.loadbalancer.servers]]
url = "http://localhost:9001"
[http.services.iotlive.loadbalancer]
[[http.services.iotlive.loadbalancer.servers]]
url = "http://localhost:14575"
[http.services.spm.loadbalancer]
[[http.services.spm.loadbalancer.servers]]
url = "http://localhost:9000"
[http.services.cdeserver.loadbalancer]
[[http.services.cdeserver.loadbalancer.servers]]
url = "http://localhost:9000"
[http.services.auth.loadbalancer]
[[http.services.auth.loadbalancer.servers]]
url = "http://localhost:9002"
[http.routers.my-api]
rule = "Host(`traefik.zhizhicloud.com`)"
##entrypoints = ["web", "web-secure"]
entrypoints = ["dashboard"]
service = "api@internal"
#middlewares = ["auth"] //打开时登录验证 test test
[http.middlewares.auth.basicAuth]
users = [
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
]
win运行traefik
./traefik