Global HTTPS Redirect using Traefik v3
When I was looking for ways to do HTTP to HTTPS redirects via Traefik I found a lot of different ways on the internet how to achieve this.
Traefik offers the option to configure the redirect via middleware which is documented here. However, I wanted to define the redirect directly at the entry point for my configuration.Traefik has also documented a way to do this. You can find it here.
EntryPoints are the network entry points into Traefik. They define the port which will receive the packets, and whether to listen for TCP or UDP.
In my traefik.toml
it now looks like this:
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
permanent = true
[entryPoints.websecure]
address = ":443"
By defining these two entry points and linking them with a redirection rule, Traefik ensures that all incoming HTTP traffic is automatically converted to HTTPS.
You can also test the permanent redirect with a simple curl -I
:
curl -I http://xfuture-blog.com
HTTP/1.1 308 Permanent Redirect
Date: Thu, 27 Feb 2025 15:15:50 GMT
Location: https://xfuture-blog.com/
Content-Length: 18
Proxy-Connection: Keep-Alive
Sources
Traefik RedirectScheme - https://doc.traefik.io/traefik/v3.3/middlewares/http/redirectscheme/#configuration-examples
Traefik EntryPoint Configuration - https://doc.traefik.io/traefik/routing/entrypoints/#configuration-examples