Http to https redirection through middlewares does not work unless globally enforced

Hi,

I've opened a very detailed issue on Github about this but it got automatically closed: Http to https redirection through middlewares does not work unless globally enforced · Issue #6995 · traefik/traefik · GitHub

In essence if you configure a router with http and https entry points and then add a middleware which redirects to https it won't work. To me this looks like a bug and not a misconfiguration, but I might be wrong.

It seems like somebody else has had a similar issue as well:

Does anybody know what I'm doing wrong? Is this actually a bug or not?

Your config directs the router to be TLS, bound to enttyPoints http(80),HTTPS(443) , is for Host whoami.domain.com and uses middleware redirect-to-https.

When you connect http to port 80 that configuration is not matched. No router on that service is http.
(You can demonstrate this by doing a request on https://whoami.domain.com:80)

Based on the commented section in the static configuration Default http - > https redirect is not what you want.

You have to define another router on that service that is on entryPoint http and does not have tls enabled. Remove http from the existing routers entryPoints too,

1 Like

Thanks for your reply!

It looks like I have missed this part of the documentation:

If you need to define the same route for both HTTP and HTTPS requests, you will need to define TWO DIFFERENT routers: one with the tls section, one without.
https://docs.traefik.io/v2.2/routing/routers/#tls

1 Like