Also, I tried this too by disabling the default redirect under command
section but it is also not working.
config
labels:
traefik.enable: "true"
traefik.docker.network: proxy
traefik.http.routers.api.rule: Host(`traefik.example.com`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))
traefik.http.routers.api.service: api@internal
traefik.http.routers.api.middlewares: auth #Auth is only setup on the router using the web entrypoint
## Middlewares
traefik.http.middlewares.auth.basicauth.users: alpha:$$1$$SEjVHN0z$$Apa3.iHJAW2dbAi6OuwDe/
### host header
traefik.http.middlewares.hosthdr.headers.stsseconds: 31536000
traefik.http.middlewares.hosthdr.headers.stsincludesubdomains: "true"
traefik.http.middlewares.hosthdr.headers.stspreload: "true"
# global redirect http to https
traefik.http.routers.http-catchall.rule: HostRegexp(`{host:(www\.)?.+}`)
traefik.http.routers.http-catchall.entrypoints: web
traefik.http.routers.http-catchall.middlewares: wwwtohttps
# Global redirection: https (www.) to https
traefik.http.routers.wwwsecure-catchall.rule: HostRegexp(`{host:(www\.).+}`)
traefik.http.routers.wwwsecure-catchall.entrypoints: websecure
traefik.http.routers.wwwsecure-catchall.tls: "true"
traefik.http.routers.wwwsecure-catchall.middlewares: wwwtohttps
# middleware: http(s)://(www.) to https://
traefik.http.middlewares.wwwtohttps.redirectregex.regex: ^https?://(?:www\.)?(.+)
traefik.http.middlewares.wwwtohttps.redirectregex.replacement: https://$${1}
traefik.http.middlewares.wwwtohttps.redirectregex.permanent: "true"
# enable https for api/dashboard
traefik.http.routers.api.tls: "true"
traefik.http.routers.api.tls.certresolver: letsencrypt
#traefik.http.routers.api.entrypoints: websecure
traefik.http.routers.api.tls.domains[0].main: traefik.example.com
# dummy port
traefik.http.services.dummyservice.loadbalancer.server.port: 1111 # In swarm mode, traefik requires a dummy Port
command:
- --api=true
- --api.dashboard=true
- --api.debug=true
- --providers.docker=true
- --providers.docker.endpoint=unix:///var/run/docker.sock
- --providers.docker.swarmMode=true
- --providers.docker.exposedbydefault=false
- --log.level=DEBUG
- --accesslog=false
- --entrypoints.web.address=:80
#- --entrypoints.web.http.redirections.entrypoint.to=websecure
#- --entrypoints.web.http.redirections.entrypoint.scheme=https
#- --entrypoints.web.http.redirections.entrypoint.permanent=true
- --entrypoints.websecure.address=:443
- --certificatesResolvers.letsencrypt.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory
#- --certificatesresolvers.letsencrypt.acme.httpchallenge=true
- --certificatesResolvers.letsencrypt.acme.tlsChallenge=true
- --certificatesresolvers.letsencrypt.acme.email=myemail@gmail.com
- --certificatesResolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
#- --certificatesResolvers.letsencrypt.acme.httpChallenge.entryPoint=web