dimanche 1 novembre 2020

How to redirect domain.com to www.domain.com using Traefik v2 and HTTP-01 challenge?

I have a domain : mydomain.com.

I host a blog under www.mydomain.com, I want to redirect people that use mydomain.com to www.mydomain.com

My proxy is traefik, and I use the HTTP-01 challenge to provide https with let's encrypt.

So far, my configuration looks like this:

"traefik.enable": "true",
"traefik.http.routers.blogGateway.rule": "Host(`www.mydomain.com`) || Host(`mydomain.com`)",
"traefik.http.routers.blogGateway.entrypoints": "web-secure",
"traefik.http.routers.blogGateway.tls.certresolver": "httpChallengeLetsEncrypt",
"traefik.http.routers.blogGateway.tls.domains[0].main": "www.mydomain.com",
"traefik.http.routers.blogGateway.tls.domains[1].main": "mydomain.com",
"traefik.http.middlewares.redirect-to-https.redirectscheme.scheme": "https",
"traefik.http.routers.blogGatewayRedirs.rule": "hostregexp(`{host:.+}`)",
"traefik.http.routers.blogGatewayRedirs.entrypoints": "web",
"traefik.http.routers.blogGatewayRedirs.middlewares": "redirect-to-https"

This work, but it expose two domain instead of one.

How can I perform a redirect from @ to www with traefik v2 ?




Aucun commentaire:

Enregistrer un commentaire