Web / Traefik Interview questions
How do you redirect HTTP traffic to HTTPS using Traefik middleware?
The RedirectScheme middleware rewrites the request's scheme, typically from http to https, and issues a redirect response instead of letting the request continue unencrypted.
http: middlewares: https-redirect: redirectScheme: scheme: https permanent: true routers: web: rule: "Host(`example.com`)" entrypoints: - web middlewares: - https-redirect
The router attached to this middleware listens on the plain web (port 80) entrypoint; when a request arrives there, the middleware fires before any service is reached and sends the client a 301 (when permanent: true) pointing to the https version of the same URL.
A common alternative achieves the same result globally via entrypoint-level redirection in the static configuration, so every router on the HTTP entrypoint redirects without needing the middleware attached individually.
More Related questions...