Skip to content

Instantly share code, notes, and snippets.

@L3houx
Created September 9, 2022 23:41
Show Gist options
  • Save L3houx/bb23d8e315fe9f8939fc3bb9a4530372 to your computer and use it in GitHub Desktop.
Save L3houx/bb23d8e315fe9f8939fc3bb9a4530372 to your computer and use it in GitHub Desktop.
Install and Configure Traefik

Commandes:

sudo apt-get install apache2-utils

htpasswd -nb admin <super-duper-password-here>

mkdir /opt/traefik

cd /opt/traefik

nano 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 = "<your_email@domain.com"
  storage = "acme.json"
  [certificatesResolvers.lets-encrypt.acme.tlsChallenge]

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

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

nano traefik_dynamic.toml

[http.middlewares.simpleAuth.basicAuth]
  users = [
    "htpasswd output here"
  ]

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

docker network create web

touch acme.json

chmod 600 acme.json

docker run -d \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v $PWD/traefik.toml:/traefik.toml \
  -v $PWD/traefik_dynamic.toml:/traefik_dynamic.toml \
  -v $PWD/acme.json:/acme.json \
  -p 80:80 \
  -p 443:443 \
  --network web \
  --name traefik \
  traefik:v2.2

Labels:

| traefik.http.routers..rule | Host(<subdomain>.<domain>) | traefik.http.routers..tls | true | traefik.http.routers..tls.certresolver | lets-encrypt | traefik.http.services..loadbalancer.server.port | 8080 | traefik.http.services..loadbalancer.server.scheme | http

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment