I have recently finished setting up Traefik with multiple configs but haven't been able to find a solution. I am using docker-compose with dynamic configurator and want to correctly redirect http to https.
tl;dr: Do I have to declare both http and https entrypoints to redirect http -> https in Traefik? Really? No better way? Not including an entrypoint-based global redirect (not considering that)
For the service whoami, to achieve a simple combo of local service + http auth + https + http redirect I need the following:
whoami: ... labels: - traefik.enable=true # External - traefik.http.routers.whoami.rule=Host(`whoami.example.com`) - traefik.http.routers.whoami.entrypoints=https - traefik.http.routers.whoami.tls.certresolver=lets-encrypt-tls - traefik.http.routers.whoami.middlewares=simpleAuth@file # External http redirect - traefik.http.routers.whoami-http.rule=Host(`whoami.example.com`) - traefik.http.routers.whoami-http.entrypoints=http - traefik.http.routers.whoami-http.middlewares=redirect-https@file # - traefik.http.routers.whoami-http.middlewares=simpleAuth@file # Do I need it at all? # Local - traefik.http.routers.whoami-local.rule=Host(`whoami.local`) - traefik.http.routers.whoami-local.entrypoints=http - traefik.http.routers.whoami-local.middlewares=simpleAuth@file Relevant configs:
### Static config: entryPoints: http: address: :80 https: address: :443 ### Dynamic config: middlewares: redirect-https: redirectScheme: scheme: https permanent: false My question is: Is there a better, more concise way to achieve the redirect? Naturally, outside of redirecting on the entrypoints level as I want to retain per-container control of redirects.
I initially thought that I could do:
# External .dev - traefik.http.routers.whoami.rule=Host(`whoami.example.com`) - traefik.http.routers.whoami.entrypoints=http, https - traefik.http.routers.whoami.tls.certresolver=lets-encrypt-tls - traefik.http.routers.whoami.middlewares=redirect-https@file However that doesn't work, unfortunately.
I would probably be more ok with it if I could store all of that in the dynamic configuration file, but because --traefik.enable=ture creates un-deletable and unmanageable from dynamic configuration routes and services (seemingly indented), I have to define all routes in the docker-compose file.
Related questions 0 traefik https only works with redirect 4 HTTPS-Redirect with Traefik behind Aws Loadbalancer 0 Traefik failing https redirection Related questions 0 traefik https only works with redirect 4 HTTPS-Redirect with Traefik behind Aws Loadbalancer 0 Traefik failing https redirection 11 Traefik v2: 404 while routing HTTP traffic globally to HTTPS 0 Traefik 2.4: redirect http to https based on IP / Header 7 traefik - HTTP to HTTPS WWW Redirect 0 Traefik. Split configuration and redirect to https Load 4 more related questions Show fewer related questions
Reset to default