How to redirect http non-www to https www?

Hi all,

I'm new from nginx, I want to redirect http non-www to https www.

Example:

http://abc.com     -> https://www.abc.com
http://www.abc.com -> https://www.abc.com
https://abc.com    -> https://www.abc.com

Thank for your help!

Which traefik version are you using 1.7.x or 2.2.x ?

I'm using Traefik 2.2.x

This example uses Labels because i mostly use traefik with docker labels.
This is just simple http 2 https forwarding for your www subdomain you have to deal with regex and some pathfrefix mappers or stuff like that i think.

  • i use 2 entrypoints
    • web:80
    • websecure:443
traefik.http.routers.app-web.entrypoints: web
traefik.http.routers.app-web.middlewares: redirect@file
traefik.http.routers.app-web.rule: Host(`app.url.com`)
traefik.http.routers.app-websecure.entrypoints: websecure
traefik.http.routers.app-websecure.tls: true
traefik.http.services.app-websecure.loadbalancer.server.port: 8080
traefik.http.routers.app-websecure.rule: Host(`app.url.com`)
  • web uses middleware "redirect@file" this middleware is defined in my dynamic_conf.toml
# redirect
[http.middlewares]
  [http.middlewares.redirect.redirectscheme]
    scheme = "https"
    permanent = true
  • dynamic_conf.toml is refernced in my (static) traefik.toml:
[providers.file]
    filename = "<traefik_path>/dynamic_conf.toml"
    watch=true

hope this helps