traefik 运行但不使用 toml 文件
traefik runs but don't uses toml-file
我在 docker 环境中设置了一个 traefik 反向代理。
目标是根据 URL/Host.
将流量重定向到不同的服务器(而不是容器)
折腾了一圈,搞定了traefik。我现在可以看到后端。
但是如果我尝试访问服务器,我会从 traefik 收到“404 页面未找到”。
tcp.routers 和 tcp.services 也没有出现在 traefik-backend 中。
混合使用 docker-compose 和 traefik.toml 作为配置时是否有限制?如果我启动 traefik,它会说,它使用 traefik.toml.
另一个问题是,没有使用 traefik-backend 的用户身份验证 - username/password 没有问题。
或者 traefik 是否忽略了整个配置,因为它无法获得证书(它只是开发而不是现在在生产中)。
docker-compose.yml:
version: "3.3"
services:
traefik:
restart: always
image: "traefik:latest"
container_name: "traefik"
ports:
- "80:80"
- "443:443"
- "8080:8080"
networks:
- traefik_proxy
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- ./17/traefik.toml:/etc/traefik/traefik.toml
- ./shared:/shared
command:
- "--api=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=traefik_proxy"
networks:
traefik_proxy:
external: true
traefik.toml:
[global]
sendAnonymousUsage = false
[log]
level = "DEBUG"
[api]
dashboard = true
insecure = true
[entryPoints]
[entryPoints.traefik]
address = ":8080"
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections]
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http.tls]
certResolver = "myresolver"
[http]
[http.routers]
[http.routers.mymiddleware]
entryPoints = ["websecure"]
rule = "Host(`cmw.domain.de`) || Host(`sync.domain.de`)"
certResolver = "myresolver"
service = "mymiddleware"
[http.routers.owncloud]
entryPoints = ["websecure"]
rule = "Host(`cloud.domain.de`)"
certResolver = "myresolver"
service = "owncloud"
[http.routers.dashboard]
entryPoints = ["traefik"]
rule = "PathPrefix(`/dashboard`) || PathPrefix(`/api`)"
service = "api@internal"
middlewares = ["auth"]
[http.middlewares.auth.basicAuth]
usersFile="shared/.htpasswd"
[tcp.services]
[tcp.services.mymiddleware]
[[tcp.services.mymiddleware.loadBalancer.servers]]
address = "192.168.92.14"
[tcp.service.owncloud]
[[tcp.services.owncloud.loadBalancer.servers]]
address = "192.168.92.10"
[certificatesResolvers.myresolver.acme]
email = "webmaster@domain.de"
storage = "acme.json"
[certificatesResolvers.myresolver.acme.httpChallenge]
entryPoint = "web"
我认为问题在于将 http 路由器与 tcp 服务混合使用。 Traefik 将搜索名为 mymiddleware
的 http 服务,但没有定义该服务。反之亦然,对于您的 tcp 服务,没有定义 tcp 路由器。我想这可以通过将 tcp.services
更改为 http.services
.
来简单地解决
但是还有一个更重要的问题:
动态配置和静态配置分开是“必须”的。
所以我得到了:
docker-compose.yml
version: "3.3"
services:
traefik:
restart: always
image: "traefik:latest"
container_name: "traefik"
ports:
- "80:80"
- "443:443"
- "8080:8080"
networks:
- traefik_proxy
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- ./traefik/traefik.toml:/etc/traefik/traefik.toml
- ./shared:/shared
networks:
traefik_proxy:
external: true
traefik/traefik.toml
[global]
sendAnonymousUsage = false
[log]
level = "DEBUG"
[api]
dashboard = true
# insecure = true
[providers.file]
filename = "shared/config.toml"
[entryPoints]
[entryPoints.traefik]
address = ":8080"
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections]
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http.tls]
certResolver = "myresolver"
[certificatesResolvers.myresolver.acme]
email = "webmaster@domain.de"
storage = "shared/acme.json"
[certificatesResolvers.myresolver.acme.httpChallenge]
entryPoint = "web"
shared/config.toml
[http]
[http.routers]
[http.routers.cudgelmiddleware]
entryPoints = ["websecure"]
rule = "Host(`cmw.domain.de`) || Host(`sync.domain.de`)"
certResolver = "myresolver"
service = "mymiddleware"
[http.routers.owncloud]
entryPoints = ["websecure"]
rule = "Host(`cloud.otherdomain.com`)"
certResolver = "myresolver"
service = "owncloud"
[http.routers.dashboard]
entryPoints = ["traefik"]
rule = "PathPrefix(`/dashboard`) || PathPrefix(`/api`)"
service = "api@internal"
middlewares = ["auth"]
[http.middlewares.auth.basicAuth]
usersFile="shared/.htpasswd"
[http.services]
[http.services.mymiddleware]
[[http.services.mymiddleware.loadBalancer.servers]]
url = "http://192.168.92.14"
[http.service.owncloud]
[[http.services.owncloud.loadBalancer.servers]]
url = "http://192.168.92.10"
我在 docker 环境中设置了一个 traefik 反向代理。 目标是根据 URL/Host.
将流量重定向到不同的服务器(而不是容器)折腾了一圈,搞定了traefik。我现在可以看到后端。 但是如果我尝试访问服务器,我会从 traefik 收到“404 页面未找到”。
tcp.routers 和 tcp.services 也没有出现在 traefik-backend 中。
混合使用 docker-compose 和 traefik.toml 作为配置时是否有限制?如果我启动 traefik,它会说,它使用 traefik.toml.
另一个问题是,没有使用 traefik-backend 的用户身份验证 - username/password 没有问题。
或者 traefik 是否忽略了整个配置,因为它无法获得证书(它只是开发而不是现在在生产中)。
docker-compose.yml:
version: "3.3"
services:
traefik:
restart: always
image: "traefik:latest"
container_name: "traefik"
ports:
- "80:80"
- "443:443"
- "8080:8080"
networks:
- traefik_proxy
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- ./17/traefik.toml:/etc/traefik/traefik.toml
- ./shared:/shared
command:
- "--api=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=traefik_proxy"
networks:
traefik_proxy:
external: true
traefik.toml:
[global]
sendAnonymousUsage = false
[log]
level = "DEBUG"
[api]
dashboard = true
insecure = true
[entryPoints]
[entryPoints.traefik]
address = ":8080"
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections]
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http.tls]
certResolver = "myresolver"
[http]
[http.routers]
[http.routers.mymiddleware]
entryPoints = ["websecure"]
rule = "Host(`cmw.domain.de`) || Host(`sync.domain.de`)"
certResolver = "myresolver"
service = "mymiddleware"
[http.routers.owncloud]
entryPoints = ["websecure"]
rule = "Host(`cloud.domain.de`)"
certResolver = "myresolver"
service = "owncloud"
[http.routers.dashboard]
entryPoints = ["traefik"]
rule = "PathPrefix(`/dashboard`) || PathPrefix(`/api`)"
service = "api@internal"
middlewares = ["auth"]
[http.middlewares.auth.basicAuth]
usersFile="shared/.htpasswd"
[tcp.services]
[tcp.services.mymiddleware]
[[tcp.services.mymiddleware.loadBalancer.servers]]
address = "192.168.92.14"
[tcp.service.owncloud]
[[tcp.services.owncloud.loadBalancer.servers]]
address = "192.168.92.10"
[certificatesResolvers.myresolver.acme]
email = "webmaster@domain.de"
storage = "acme.json"
[certificatesResolvers.myresolver.acme.httpChallenge]
entryPoint = "web"
我认为问题在于将 http 路由器与 tcp 服务混合使用。 Traefik 将搜索名为 mymiddleware
的 http 服务,但没有定义该服务。反之亦然,对于您的 tcp 服务,没有定义 tcp 路由器。我想这可以通过将 tcp.services
更改为 http.services
.
但是还有一个更重要的问题:
动态配置和静态配置分开是“必须”的。
所以我得到了:
docker-compose.yml
version: "3.3"
services:
traefik:
restart: always
image: "traefik:latest"
container_name: "traefik"
ports:
- "80:80"
- "443:443"
- "8080:8080"
networks:
- traefik_proxy
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- ./traefik/traefik.toml:/etc/traefik/traefik.toml
- ./shared:/shared
networks:
traefik_proxy:
external: true
traefik/traefik.toml
[global]
sendAnonymousUsage = false
[log]
level = "DEBUG"
[api]
dashboard = true
# insecure = true
[providers.file]
filename = "shared/config.toml"
[entryPoints]
[entryPoints.traefik]
address = ":8080"
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections]
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http.tls]
certResolver = "myresolver"
[certificatesResolvers.myresolver.acme]
email = "webmaster@domain.de"
storage = "shared/acme.json"
[certificatesResolvers.myresolver.acme.httpChallenge]
entryPoint = "web"
shared/config.toml
[http]
[http.routers]
[http.routers.cudgelmiddleware]
entryPoints = ["websecure"]
rule = "Host(`cmw.domain.de`) || Host(`sync.domain.de`)"
certResolver = "myresolver"
service = "mymiddleware"
[http.routers.owncloud]
entryPoints = ["websecure"]
rule = "Host(`cloud.otherdomain.com`)"
certResolver = "myresolver"
service = "owncloud"
[http.routers.dashboard]
entryPoints = ["traefik"]
rule = "PathPrefix(`/dashboard`) || PathPrefix(`/api`)"
service = "api@internal"
middlewares = ["auth"]
[http.middlewares.auth.basicAuth]
usersFile="shared/.htpasswd"
[http.services]
[http.services.mymiddleware]
[[http.services.mymiddleware.loadBalancer.servers]]
url = "http://192.168.92.14"
[http.service.owncloud]
[[http.services.owncloud.loadBalancer.servers]]
url = "http://192.168.92.10"