首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Traefik重定向域到子域

Traefik重定向域到子域
EN

Stack Overflow用户
提问于 2021-02-27 15:19:13
回答 1查看 2.3K关注 0票数 0

我希望在TLS环境中将所有请求永久地重定向到example.comwww.example.comblog.example.com

我的当前配置:

traefik.toml

代码语言:javascript
复制
[entryPoints]
  [entryPoints.web]
    address = ":80"
    [entryPoints.web.http.redirections.entryPoint]
      to = "websecure"
      scheme = "https"

  [entryPoints.websecure]
    address = ":443"

[providers.docker]
  exposedbydefault = false
  watch = true
  network = "web"
[providers.file]
  filename = "traefik_dynamic.toml"

[certificatesResolvers.lets-encrypt.acme]
  email = "mymail@example.com"
  storage = "/letsencrypt/acme.json"
  [certificatesResolvers.lets-encrypt.acme.dnsChallenge]
    provider = "myprovider"

traefik_dynamic.toml

代码语言:javascript
复制
[http.middlewares] 
  [http.middlewares.goToBlog.redirectregex] 
    regex = "^https://(.*)example.com/(.*)" 
    replacement = "https://blog.example.com/$${2}"
    permanent = true
 
[http.routers] 
  [http.routers.gotoblog] 
    rule = "Host(`example.com`) || Host(`www.example.com`)" 
    entrypoints = ["websecure"] 
    middlewares = ["goToBlog"] 
    service = "noop@internal" 
    [http.routers.gotoblog.tls] 
      certResolver = "lets-encrypt"

当我试图访问example.com时,它会给出一个SSL错误。包括blog.example.com在内的所有其他端点都在工作。我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-28 11:07:27

好吧,显然这和我的重定向配置无关。看上去就像在码头上搭便车,和ACME certificates timeout with traefik很相似。就等了一天,一切都如期而至。只有两个小的更新来更正重定向配置。也许有一个更优雅的解决方案。

traefik_dynamic.toml

代码语言:javascript
复制
[http.middlewares] 
  [http.middlewares.goToBlog.redirectregex] 
    regex = "^https://(.*)example.com/(.*)" 
    replacement = "https://blog.example.com/${2}"         # no double $$
    permanent = true
 
[http.routers] 
  [http.routers.gotoblog] 
    rule = "Host(`example.com`, `www.example.com`)"       # just an array of domains is fine, too
    entrypoints = ["websecure"] 
    middlewares = ["goToBlog"] 
    service = "noop@internal" 
    [http.routers.gotoblog.tls] 
      certResolver = "lets-encrypt"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66400248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档