Traefik: Managing Self-Hosted Applications

by Müller | Nov 15, 2025 | Sysadmin | 0 comments

Hosting your own web applications is a challenging task. This post explores how Traefik can simplify that process, working as an efficient gateway and a modern load balancer.

Setting Up DNS: The First Step

Before implementing Traefik, it’s crucial to have a solid DNS setup. Here is a real example using mfs.eng.br. This configuration ensures requests are correctly forwarded to the server:

Resource TTL Type Priority Data
*.mfs.eng.br 86400 A 0 <YOUR_SERVER_IP>
mfs.eng.br 86400 A 0 <YOUR_SERVER_IP>

Why Traefik Matters

Traefik acts as an efficient gateway for your applications. It manages traffic, distributes requests, and automatically detects new Docker containers, creating routes for them with no manual configuration required.

Automatic SSL/TLS: The Let’s Encrypt integration generates and renews certificates automatically, bringing security without friction.

Hosting Self-Hosted Applications

If you host your own applications, Traefik is your best ally. It automates critical tasks and simplifies exposing applications to the internet.

Below is the configuration for a fully functional Traefik server with automatic SSL:


version: "3.3"

services:
  traefik:
    image: "traefik:v2.10"
    container_name: "traefik"
    command:
      - "--api.insecure=true"
      - "--log.level=DEBUG"
      - "--log.filePath=/logs/traefik.log"
      - "--accessLog.filePath=/logs/access.log"
      - "--accessLog.bufferingSize=100"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=true"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.myresolver.acme.httpchallenge=true"
      - "--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web"
      - "--certificatesresolvers.myresolver.acme.email=<YOUR_EMAIL>"
      - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
      - "127.0.0.1:8080:8080"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - "./letsencrypt:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./logs:/logs"

networks:
  default:
    external:
      name: proxy_network
  

And here is an example application configured to be exposed with its own domain via Traefik:


version: '3.8'

services:
  web:
    image: nginx:alpine
    volumes:
      - ./html:/usr/share/nginx/html
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.cltpj.loadbalancer.server.port=80"
      - "traefik.routers.cltpj.rule=Host(`clt-pj.mfs.eng.br`)"
      - "traefik.http.routers.cltpj.entrypoints=websecure"
      - "traefik.http.routers.cltpj.tls.certresolver=myresolver"

      - "traefik.http.routers.cltpj-http.rule=Host(`clt-pj.mfs.eng.br`)"
      - "traefik.http.routers.cltpj-http.entrypoints=web"
      - "traefik.http.routers.cltpj-http.middlewares=redirect-to-https@docker"

      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"

networks:
  default:
    external:
      name: proxy_network
  

Conclusion

Adopting Traefik for your self-hosted applications means saving time and effort while guaranteeing security. It’s a smart choice for anyone looking to simplify web application management.

I hope this guide helped!

Table of Contents