How to disable http redirect to https for a single container domain?

In fact, it's possible for a router, by playing with priority: if the router has a higher priority than the router with the redirection, the router will be excluded from the redirection.

example 1
version: '3.7'

services:

  # curl -L -k http://traefik.localhost (redirect to https://traefik.localhost)
  # curl http://whoami.localhost (no redirection)
  # curl -L -k http://example.localhost (redirect to https://example.localhost)

  traefik:
    image: traefik:v2.2
    command:
      - --log.level=INFO
      - --api
      - --providers.docker.exposedbydefault=false
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    labels:
      traefik.enable: 'true'

      # Dashboard
      traefik.http.routers.traefik.rule: Host(`traefik.localhost`)
      traefik.http.routers.traefik.entrypoints: websecure
      traefik.http.routers.traefik.tls: 'true'
      traefik.http.routers.traefik.service: api@internal

      # global redirect to https
      traefik.http.routers.http-catchall.rule: hostregexp(`{host:.+}`)
      traefik.http.routers.http-catchall.entrypoints: web
      traefik.http.routers.http-catchall.middlewares: redirect-to-https
      traefik.http.routers.http-catchall.priority: 1000

      # middleware redirect
      traefik.http.middlewares.redirect-to-https.redirectscheme.scheme: https

  whoami:
    image: containous/whoami:v1.5.0
    labels:
      traefik.enable: 'true'

      traefik.http.routers.aaa.rule: Host(`whoami.localhost`)
      traefik.http.routers.aaa.entrypoints: web
      traefik.http.routers.aaa.priority: 2000

      traefik.http.routers.bbb.rule: Host(`example.localhost`)
      traefik.http.routers.bbb.entrypoints: websecure
example 2
version: '3.7'

services:

  # curl -L -k http://traefik.localhost (redirect to https://traefik.localhost)
  # curl http://whoami.localhost (no redirection)
  # curl -L -k http://example.localhost (redirect to https://example.localhost)

  traefik:
    image: traefik:v2.2.10
    command:
      - --log.level=INFO
      - --api
      - --providers.docker.exposedbydefault=false
      
      - --entrypoints.web.address=:80
      # global redirect to https
      - --entrypoints.web.http.redirections.entryPoint.to=websecure
      - --entrypoints.web.http.redirections.entrypoint.scheme=https
      - --entrypoints.web.http.redirections.entrypoint.priority=1000

      - --entrypoints.websecure.address=:443
      - --entrypoints.websecure.http.tls=true
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    labels:
      traefik.enable: 'true'

      # Dashboard
      traefik.http.routers.traefik.rule: Host(`traefik.localhost`)
      traefik.http.routers.traefik.entrypoints: web,websecure
      traefik.http.routers.traefik.service: api@internal

  whoami:
    image: containous/whoami:v1.5.0
    labels:
      traefik.enable: 'true'

      traefik.http.routers.aaa.rule: Host(`whoami.localhost`)
      traefik.http.routers.aaa.entrypoints: web
      traefik.http.routers.aaa.priority: 2000

      traefik.http.routers.bbb.rule: Host(`example.localhost`)
      traefik.http.routers.bbb.entrypoints: web,websecure
3 Likes