0

Just started using traefik. if i access www.myappdomain.com, its insecure and wont redirect to https. Please all this versioning of apps are very confusing. I am still uising .toml and configured both static and dynamic traefik files. Please can someone direct me on how to redirect using the regex as what i have tried havent worked in v2.2. Below is my docker-compose.yaml:

version: '3.9'
services:
  traefik:
    image: 'traefik:v2.2'
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'
      - '$PWD/traefik/traefik.toml:/traefik.toml'
      - '$PWD/traefik/traefik_dynamic.toml:/traefik_dynamic.toml'
      - '$PWD/traefik/acme.json:/acme.json'
    ports:
      - '80:80'
      - '443:443'
    restart: always
    networks: 
      - web
    container_name: traefik


  postgres:
    image: postgres:13-alpine
    restart: always
    container_name: postgres
    depends_on:
      - traefik
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
    volumes:
      - /home/development/db_data:/var/lib/postgresql/data
    networks:
      - web
  app:
    image: golang
    ports:
      - "8080:8080"
    restart: always
    environment:
      - DB_SOURCE
    depends_on:
      - postgres
    networks:
      - web
    entrypoint: [ "/app/wait-for.sh", "app:5432", "--", "/app/start.sh" ]
    command: [ "/app/main" ]
    container_name: golang-app
    labels:
      - traefik.http.routers.app.rule=Host(`mayapp.com`)
      - traefik.http.routers.app.tls=true
      - traefik.http.routers.app.tls.certresolver=lets-encrypt
      - "traefik.port=8080"
volumes:
  db-data:
secrets:
  db-password:
    file: docker/db/password.txt
networks:
  web:
    external: true

For the static traefik.toml

[entryPoints]
  [entryPoints.web]
    address = ":80"
    [entryPoints.web.http.redirections.entryPoint]
      to = "websecure"
      scheme = "https"

  [entryPoints.websecure]
    address = ":443"

[api]
  dashboard = true

[certificatesResolvers.lets-encrypt.acme]
  email = "admin@app.com"
  storage = "acme.json"
  [certificatesResolvers.lets-encrypt.acme.tlsChallenge]

[providers.docker]
  watch = true
  network = "web"

[providers.file]
  filename = "traefik_dynamic.toml"

For the traefik_dynamic.toml

[http.middlewares.simpleAuth.basicAuth]
  users = [
    "admin:$appapppapppapapapappapappa/"
  ]

[http.routers.api]
  rule = "Host(`monitor.app.com`)"
  entrypoints = ["websecure"]
  middlewares = ["simpleAuth"]
  service = "api@internal"
  [http.routers.api.tls]
    certResolver = "lets-encrypt"

I have tried adding labels to the traefik container, but it still wont make www secure. Please can someone point me in the right direction? thank you

pythonGo
  • 125
  • 2
  • 12

0 Answers0