[英]Traefik Redirect Domain to Subdomain
I want to permanently redirect all requests to example.com
and www.example.com
to blog.example.com
in a TLS environment.我想在 TLS 环境中将所有请求永久重定向到
example.com
和www.example.com
到blog.example.com
。
My current config:我目前的配置:
traefik.toml : 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 : traefik_dynamic.toml :
[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"
When I try to access example.com
it gives my an SSL Protocol Error.当我尝试访问
example.com
时,它给了我一个 SSL 协议错误。 All my other endpoints including blog.example.com
are working.我的所有其他端点,包括
blog.example.com
都在工作。 What am I doing wrong?我究竟做错了什么?
Okey, obviously it had nothing to do with my redirect configuration.好吧,显然这与我的重定向配置无关。 Seemed like a hickup in traefik / docker, similar to ACME certificates timeout with traefik .
似乎是 traefik / docker 中的一个小插曲,类似于 traefik 的ACME 证书超时。 Just waited one day and everything worked as expected.
只等了一天,一切都按预期进行。 Just two minor updates to correct the redirect configuration.
只需两个小更新即可更正重定向配置。 Maybe there's a more elegant solution.
也许有一个更优雅的解决方案。
traefik_dynamic.toml : traefik_dynamic.toml :
[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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.