首页 文章

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

提问于
浏览
1

我正在使用traefik和docker在我的服务器上运行多个服务 . 如果(子)域没有匹配的容器,我如何指定默认容器或回退容器?例如,我使用example.com作为我的网站,使用cloud.example.com作为我的nextcloud . 但是当有人使用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

1 回答

  • 2

    如果您希望除了几个子域之外的所有流量都转到您的Web容器:

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

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

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

相关问题