Traefik 将域重定向到子域
Traefik Redirect Domain to Subdomain
我想在 TLS 环境中将所有请求永久重定向到 example.com
和 www.example.com
到 blog.example.com
。
我当前的配置:
traefik.toml:
[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:
[http.middlewares]
[http.middlewares.goToBlog.redirectregex]
regex = "^https://(.*)example.com/(.*)"
replacement = "https://blog.example.com/$"
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
都在工作。我做错了什么?
好的,显然这与我的重定向配置无关。看起来像是 traefik / docker 中的小问题,类似于 ACME certificates timeout with traefik。只等了一天,一切都按预期进行。只需两个小更新即可更正重定向配置。也许有更优雅的解决方案。
traefik_dynamic.toml:
[http.middlewares]
[http.middlewares.goToBlog.redirectregex]
regex = "^https://(.*)example.com/(.*)"
replacement = "https://blog.example.com/" # 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"
我想在 TLS 环境中将所有请求永久重定向到 example.com
和 www.example.com
到 blog.example.com
。
我当前的配置:
traefik.toml:
[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:
[http.middlewares]
[http.middlewares.goToBlog.redirectregex]
regex = "^https://(.*)example.com/(.*)"
replacement = "https://blog.example.com/$"
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
都在工作。我做错了什么?
好的,显然这与我的重定向配置无关。看起来像是 traefik / docker 中的小问题,类似于 ACME certificates timeout with traefik。只等了一天,一切都按预期进行。只需两个小更新即可更正重定向配置。也许有更优雅的解决方案。
traefik_dynamic.toml:
[http.middlewares]
[http.middlewares.goToBlog.redirectregex]
regex = "^https://(.*)example.com/(.*)"
replacement = "https://blog.example.com/" # 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"