Open2

Traefikでリバースプロキシ

海都海都
traefik.static.yaml
entryPoints:
  web:
    address: ":80"

  websecure:
    address: ":443"

certificatesResolvers:
  myresolver:
    acme:
      email: <メールアドレス>
      storage: /traefik/acme/acme.json
      httpChallenge:
        entryPoint: web

providers:
  file:
    filename: /traefik/config/traefik.dynamic.yaml
    watch: true
traefik.dynamic.yaml
http:
  routers:
    web:
      entryPoints:
        - web
      rule: Host(`<ホスト名>`)
      service: alb
      middlewares:
        - redirectToHttps

    websecure:
      entryPoints:
        - websecure
      rule: Host(`<ホスト名>`)
      service: alb
      middlewares:
        - auth
      tls:
        certResolver: myresolver

  middlewares:
    redirectToHttps:
      redirectScheme:
        scheme: https
        permanent: true
    auth:
      basicAuth:
        users:
          - <ユーザー名>:<パスワードハッシュ>
        removeHeader: true

  services:
    alb:
      loadBalancer:
        servers:
          - url: <プロキシ先IPまたはURL>
compose.yaml
services:
  traefik:
    image: traefik:v3.0
    ports:
      - 80:80
      - 443:443
    command:
      - --configFile=/traefik/config/traefik.static.yaml
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.static.yaml:/traefik/config/traefik.static.yaml
      - ./traefik.dynamic.yaml:/traefik/config/traefik.dynamic.yaml
      - acme:/traefik/acme
    security_opt:
      - no-new-privileges:true
    restart: always

volumes:
  acme:
海都海都

Basic認証用のパスワードハッシュは

$ htpasswd -nB <ユーザー名>

で作成することが出来る