traefik 中的默认或后备容器 (docker)
Default or fallback container (docker) in traefik
我在我的服务器上使用 traefik 和 docker 到 运行 多项服务。如果(子)域没有匹配的容器,我如何指定默认或后备容器?例如,我为我的网站和云使用 example.com。为我的 nextcloud 使用 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
.
然后在回退到您的网站之前,为您想要匹配的任何其他服务设置更高的优先级。
我在我的服务器上使用 traefik 和 docker 到 运行 多项服务。如果(子)域没有匹配的容器,我如何指定默认或后备容器?例如,我为我的网站和云使用 example.com。为我的 nextcloud 使用 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
.
然后在回退到您的网站之前,为您想要匹配的任何其他服务设置更高的优先级。