Global Docker HTTPS redirect using TOML

Hi,

I am struggling to get the Global HTTPS redirect to work when using docker and the traefik.toml to set the settings in V2. I have followed the blog post, the other forum posts here but none seem to do it in the TOML file and when translating the docker-compose to TOML it won't work - keep getting a 404 error when accessing HTTP sites with no redirect. HTTPS works fine.

Traefik.toml:


[entryPoints]
  [entryPoints.web]
    address = ":80"

  [entryPoints.web-secure]
    address = ":443"
[certificatesResolvers.portainer.acme]
  email = "xxx@email.com"
  storage = "acme.json"
  [certificatesResolvers.portainer.acme.dnsChallenge]
    provider = "digitalocean"
    delayBeforeCheck = 90
    resolvers = ["1.1.1.1:53", "8.8.8.8:53"]

[providers.docker]
[providers.docker]
  endpoint = "unix:///var/run/docker.sock"
  exposedByDefault = false
  network = "portainer"

[api]
  dashboard = true
  insecure = true

[log]
  filePath = "/logs/traefik.log"
  level = "DEBUG"

[accessLog]
  filePath = "/logs/access.log"

# Global https redirect

# Defining the middleware doing the work
[http.middlewares]
  [http.middlewares.redirect-to-https.redirectScheme]
    scheme = "https"
    permanent = true


# Defining what route will use the middleware
[http.routers]
  [http.routers.redirs]
    rule = "HostRegexp(`{host:.+}`)"
    entryPoints = ["web"]
    middlewares = ["redirect-to-https"]

And the specific docker container labels:

traefik.enable = true
traefik.http.routers.onlyoffice.entrypoints = web-secure
traefik.http.routers.onlyoffice.rule = Host(`xxx.xxx.com`)
traefik.http.routers.onlyoffice.tls.certresolver = portainer
traefik.http.services.onlyoffice.loadbalancer.server.port = 80

Thank you for any help!

Hello,

To use the file provider (dynamic configuration from a file) to have to activate it (like for Traefik v1).

Also in Traefik v2, you have to use different file for the static configuration and the dynamic configuration.

traefik.toml

[entryPoints]
  [entryPoints.web]
    address = ":80"

  [entryPoints.web-secure]
    address = ":443"

[api]
  dashboard = true
  insecure = true

[log]
  filePath = "/logs/traefik.log"
  level = "DEBUG"

[accessLog]
  filePath = "/logs/access.log"

[certificatesResolvers.portainer.acme]
  email = "xxx@email.com"
  storage = "acme.json"
  [certificatesResolvers.portainer.acme.dnsChallenge]
    provider = "digitalocean"
    delayBeforeCheck = 90
    resolvers = ["1.1.1.1:53", "8.8.8.8:53"]

[providers.docker]
  endpoint = "unix:///var/run/docker.sock"
  exposedByDefault = false
  network = "portainer"

[providers.file]
  directory = "/path/to/dyn/"

/path/to/dyn/myfile.toml

# Global https redirect
[http.routers]
  [http.routers.redirecttohttps]
    entryPoints = ["web"]
    middlewares = ["httpsredirect"]
    rule = "HostRegexp(`{host:.+}`)"
    service = "noop"

[http.services]
  # noop service, the URL will be never called
  [http.services.noop.loadBalancer]
    [[http.services.noop.loadBalancer.servers]]
      url = "http://192.168.0.1"

[http.middlewares]
  [http.middlewares.httpsredirect.redirectScheme]
    scheme = "https"
    permanent = true

Recommend read:

1 Like