I looked for answers here: How to redirect http to https with Traefik 2.0 and Docker Compose labels? - Stack Overflow
But none helped
version: '2.1'
services:
nginx-mailcow:
networks:
# Add Traefik's network
- web
labels:
- "traefik.enable=true"
- "traefik.http.routers.moo.rule=Host(`${MAILCOW_HOSTNAME}`)"
- "traefik.http.routers.moo.tls=true"
- "traefik.http.routers.moo.tls.certresolver=le"
- "traefik.http.services.moo.loadbalancer.server.port=${HTTP_PORT}"
- "traefik.http.routers.moo.entrypoints=websecure"
- "traefik.http.middlewares.moo-redirectscheme.redirectscheme.scheme=https"
# - traefik.http.routers.moo.entrypoints=web"
# - traefik.http.routers.http-moo.middlewares=redirect-to-https
- "traefik.http.middlewares.moo-r.redirectscheme.scheme=https"
- "traefik.http.middlewares.moo-r.redirectscheme.permanent=true"
- "traefik.http.routers.moo.middlewares=moo-r"
- "traefik.docker.network=terafik_default"
certdumper:
image: humenius/traefik-certs-dumper
command: --restart-containers ${COMPOSE_PROJECT_NAME}-postfix-mailcow-1,${COMPOSE_PROJECT_NAME}-nginx-mailcow-1,${COMPOSE_PROJECT_NAME}-dovecot-mailcow-1
# network_mode: none
volumes:
# Mount the volume which contains Traefik's `acme.json' file
# Configure the external name in the volume definition
- /opt/traefik/letsencrypt/:/traefik:ro
# Mount mailcow's SSL folder
- ./data/assets/ssl/:/output:rw
# Mount docker socket to restart containers
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: always
environment:
# only change this, if you're using another domain for mailcow's web frontend compared to the standard config
- DOMAIN=${MAILCOW_HOSTNAME}
networks:
web:
external:
# Name of the external network
name: terafik_default
#volumes:
# acme:
# external:
# Name of the external docker volume which contains Traefik's `acme.json' file
# name: acme
# Traefik 2 (2.0.7) config file.
# Enables accesslog
[accessLog]
# Providers (platform which traefik will connect with).
[providers]
[providers.docker]
exposedByDefault = false # Disable automatic rules for running containers. Used to avoid un-used rules, you can enable it if youre curious tho.
endpoint = "unix:///var/run/docker.sock" # links the docker socket to traefik. Used to allow traefik to manage docker.
# Entrypoints (exposed ports that traefik will listen to trough tcp)
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.websecure]
address = ":443"
# Api (api and traefik's dashboard (automatically exposed on port 8080))
[api]
insecure = true
dashboard = true
# Acme (ACME config with the basic le (Lets Encrypt) config, domains will be specified on each container via labels, or here.
[certificatesresolvers.le.acme]
email = "mail"
storage = "acme.json" # Path where our acme file will be generated, in this case "./acme.json".
tlschallenge = "true"
[certificatesresolvers.le.acme.httpChallenge]
entryPoint = "web"
# dnsChallege is not mandatory but it can be used for wildcard certificates.
[certificatesResolvers.le.acme.dnsChallenge]
provider = "digitalocean"
delayBeforeCheck = 5
#[tls.stores]
# [tls.stores.default.defaultGeneratedCert]
# resolver = "le"
# [tls.stores.default.defaultGeneratedCert.domain]
# main = ""
# sans = ["", ""]
Http don't get redirected to https but instead ' 404 page not found '