gpt4 book ai didi

docker - traefik 中的默认或后备容器 (docker)

转载 作者:行者123 更新时间:2023-12-02 18:21:43 24 4
gpt4 key购买 nike

我正在使用 traefik 和 docker 在我的服务器上运行多个服务。如果(子)域没有匹配的容器,我如何指定默认或后备容器?例如,我为我的网站使用 example.com,为我的 nextcloud 使用 cloud.example.com。但是当有人使用 www.example.com 或 wiki.example(或其他可能的子域之一)时,它应该重定向到我的网站并且不显示 404 错误页面。

每个容器都有以下标签:

  - traefik.port=<port>
- traefik.frontend.rule=Host:<sub-1>.example.com,<sub-2>.example.com
- traefik.frontend.entryPoints=http,https

traefik 配置在这里(我使用的是 traefik:1.6-alpine 图片):

# General
logLevel = "INFO"

# EntryPoints
[entryPoints]
[entryPoints.http]
address = ":80"

[entryPoints.http.redirect]
entryPoint = "https"

[entryPoints.https]
address = ":443"

[entryPoints.https.tls]

# Let's Encrypt
[acme]
entryPoint = "https"
email = "info@example.com"
storage = "/etc/traefik/acme/acme.json"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
[[acme.domains]]
main = "example.com"

# Docker
[docker]
domain = "localhost"
watch = true

最佳答案

如果您希望所有 流量但少数子域进入您的网络容器:

替换:traefik.frontend.rule=Host:<sub-1>.example.com,<sub-2>.example.com

与:traefik.frontend.rule=HostRegexp:{subdomain:[a-z0-9]+}.example.com ,并添加优先级标签 10:traefik.frontend.priority=10 .

然后在回退到您的网站之前,为您想要匹配的任何其他服务设置更高的优先级。

关于docker - traefik 中的默认或后备容器 (docker),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51375170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com