Traefik as a reverse proxy

maxlimgj

Lim Guan Ji

Posted on January 2, 2021

Traefik as a reverse proxy

This guide is about sharing how I setup Traefik as a reverse proxy with https connection

1.Setup for apache2-utils to encrypt your password

apt install apach2-utils
Enter fullscreen mode Exit fullscreen mode

Alt Text

In this Docker file, you can change several value to your custom domain needs, the comments briefly explains the usage of the configurations.

Docker-Compose

version: '3'
services:
  traefik:
    image: traefik:latest
    container_name: traefik
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true #Prevents the UID transition while running a set UID binary
    networks:
      - proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - /etc/localtime:/etc/localtime:ro #Ensure that docker date matches server time
      - /var/run/docker.sock:/var/run/docker.sock:ro 
      - ./data/traefik.yml:/traefik.yml:ro #traefik configuration files
      - ./data/acme.json:/acme.json #to tell traefik to save ssl certs here
    command:
      --api.insecure=true # Enabling insecure api, NOT RECOMMENDED FOR PRODUCTION

    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.entrypoints=http"
      - "traefik.http.routers.traefik.rule=Host(`traefik.domain.com`)"
      - "traefik.http.middlewares.traefik-auth.basicauth.users= admin:@@$apr1@@$buoyPbo.@@$NOlqTVpSHfumf9lOiMYwI1" #Generated password
      - "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
      - "traefik.http.routers.traefik-secure.entrypoints=https"
      - "traefik.http.routers.traefik-secure.rule=Host(`traefik.domain.com`)"
      - "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
      - "traefik.http.routers.traefik-secure.tls=true"
      - "traefik.http.routers.traefik-secure.tls.certresolver=http"
      - "traefik.http.routers.traefik-secure.service=api@internal"
networks:
  proxy:
    external: true
Enter fullscreen mode Exit fullscreen mode
api:
  dashboard: true
entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"
providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
certificatesResolvers:
  http:
    acme:
      email: <<email.com>>
      storage: acme.json
      httpChallenge:
        entryPoint: http
Enter fullscreen mode Exit fullscreen mode

Start docker container

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Your good to go!!!
Alt Text

💖 💪 🙅 🚩
maxlimgj
Lim Guan Ji

Posted on January 2, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related