+
flask
rest
+
^
+
+
_
+
+
koa
fastapi
+
+
lisp
+
โˆฉ
koa
lua
terraform
+
bsd
jest
redis
haiku
+
+
โˆˆ
+
scheme
+
py
+
jwt
+
+
โ‰ 
+
+
keras
+
bitbucket
+
nuxt
::
svelte
+
surrealdb
+
+
+
vscode
+
rollup
s3
choo
centos
+
wsl
ts
+
+
+
+
*
torch
+
+
+
npm
php
+
<=
+
+
@
+
+
+
+
+
bundler
+
jax
+
+
+
fortran
+
ractive
Back to Blog
๐ŸŒ Traefik Reverse Proxy & Load Balancer on AlmaLinux: Modern Traffic Management
traefik reverse-proxy almalinux

๐ŸŒ Traefik Reverse Proxy & Load Balancer on AlmaLinux: Modern Traffic Management

Published Aug 29, 2025

Master Traefik on AlmaLinux! Learn installation, routing, SSL certificates, Docker integration, and load balancing. Perfect beginner's guide to cloud-native proxying!

5 min read
0 views
Table of Contents

๐ŸŒ Traefik Reverse Proxy & Load Balancer on AlmaLinux: Modern Traffic Management

Welcome to the future of traffic management! ๐ŸŽ‰ Ready to route web traffic like a pro? Traefik is the cloud-native reverse proxy that configures itself automatically! Itโ€™s like having an intelligent traffic controller that learns your infrastructure and adapts instantly! Think of it as GPS for your web traffic! ๐Ÿ—บ๏ธโœจ

๐Ÿค” Why is Traefik Important?

Traefik revolutionizes how we manage web traffic! ๐Ÿš€ Hereโ€™s why itโ€™s amazing:

  • ๐Ÿ”„ Auto-Configuration - Discovers services automatically, no restarts!
  • ๐Ÿ”’ Automatic SSL - Free Letโ€™s Encrypt certificates with zero config
  • ๐Ÿณ Docker Native - Works with containers out of the box
  • โšก Real-Time Updates - Changes apply instantly without downtime
  • ๐Ÿ“Š Built-in Dashboard - Beautiful UI to monitor everything
  • ๐ŸŽฏ Smart Load Balancing - Distributes traffic intelligently

Itโ€™s like having a super-smart traffic cop for your applications! ๐Ÿ‘ฎ

๐ŸŽฏ What You Need

Before managing your traffic, ensure you have:

  • โœ… AlmaLinux server (8 or 9)
  • โœ… Root or sudo access
  • โœ… At least 2GB RAM
  • โœ… Docker installed (optional but recommended)
  • โœ… Domain name (for SSL)
  • โœ… Enthusiasm for automation! ๐Ÿค–

๐Ÿ“ Step 1: Installing Traefik - Your Traffic Controller!

Letโ€™s install Traefik using multiple methods! ๐Ÿ—๏ธ

Method 1: Binary Installation (Simplest)

# Download latest Traefik binary
wget https://github.com/traefik/traefik/releases/download/v3.0.0/traefik_v3.0.0_linux_amd64.tar.gz

# Extract the binary
tar -xzf traefik_v3.0.0_linux_amd64.tar.gz

# Move to system location
sudo mv traefik /usr/local/bin/
sudo chmod +x /usr/local/bin/traefik

# Verify installation
traefik version
# Install Docker if not already installed
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker

# Pull Traefik image
docker pull traefik:v3.0

# Verify
docker run --rm traefik:v3.0 version

Create Traefik directories:

# Create configuration directory
sudo mkdir -p /etc/traefik
sudo mkdir -p /etc/traefik/dynamic

# Create data directory for certificates
sudo mkdir -p /var/lib/traefik

# Create logs directory
sudo mkdir -p /var/log/traefik

Great! Traefik is ready! ๐ŸŽ‰

๐Ÿ”ง Step 2: Basic Configuration - Setting Up Your Routes!

Letโ€™s configure Traefik with a static configuration! ๐ŸŽฏ

Create the main configuration:

# Create static configuration
sudo nano /etc/traefik/traefik.yml

Add this configuration:

# Static Configuration
global:
  checkNewVersion: true
  sendAnonymousUsage: false

# API and Dashboard
api:
  dashboard: true  # Enable the dashboard
  debug: true      # Enable debug mode

# Entry Points - where Traefik listens
entryPoints:
  web:
    address: ":80"  # HTTP
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
  websecure:
    address: ":443"  # HTTPS

# Providers - where Traefik finds services
providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false  # Only expose containers explicitly
    network: traefik-net
  file:
    directory: /etc/traefik/dynamic
    watch: true  # Watch for changes

# Certificate Resolvers - automatic SSL
certificatesResolvers:
  letsencrypt:
    acme:
      email: [email protected]  # Change this!
      storage: /var/lib/traefik/acme.json
      httpChallenge:
        entryPoint: web
      # Staging server for testing (remove for production)
      # caServer: https://acme-staging-v02.api.letsencrypt.org/directory

# Logging
log:
  level: INFO  # DEBUG, INFO, WARN, ERROR
  filePath: /var/log/traefik/traefik.log

accessLog:
  filePath: /var/log/traefik/access.log

Create systemd service:

# Create service file
sudo nano /etc/systemd/system/traefik.service

Add:

[Unit]
Description=Traefik Reverse Proxy
Documentation=https://doc.traefik.io/traefik/
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/traefik --configfile=/etc/traefik/traefik.yml
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Start Traefik:

# Create certificate file with proper permissions
sudo touch /var/lib/traefik/acme.json
sudo chmod 600 /var/lib/traefik/acme.json

# Start service
sudo systemctl daemon-reload
sudo systemctl enable traefik
sudo systemctl start traefik

# Check status
sudo systemctl status traefik

๐ŸŒŸ Step 3: Docker Integration - Auto-Discovery Magic!

Letโ€™s make Traefik work with Docker containers! ๐Ÿณ

Create Docker network:

# Create dedicated network for Traefik
docker network create traefik-net

Run Traefik with Docker Compose:

# Create docker-compose.yml
nano docker-compose.yml

Add:

version: '3.8'

services:
  traefik:
    image: traefik:v3.0
    container_name: traefik
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    networks:
      - traefik-net
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"  # Dashboard
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./traefik.yml:/traefik.yml:ro
      - ./dynamic:/dynamic:ro
      - ./acme.json:/acme.json
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dashboard.rule=Host(`traefik.example.com`)"
      - "traefik.http.routers.dashboard.entrypoints=websecure"
      - "traefik.http.routers.dashboard.tls.certresolver=letsencrypt"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.middlewares=auth"
      - "traefik.http.middlewares.auth.basicauth.users=admin:$$2y$$10$$..."  # Generate with htpasswd

networks:
  traefik-net:
    external: true

Start with Docker Compose:

# Start Traefik
docker-compose up -d

# Check logs
docker-compose logs -f traefik

โœ… Step 4: Routing Your First Application - See It Work!

Letโ€™s route traffic to a sample application! ๐Ÿš€

Deploy a simple web app:

# Run a sample app with Traefik labels
docker run -d \
  --name whoami \
  --network traefik-net \
  --label "traefik.enable=true" \
  --label "traefik.http.routers.whoami.rule=Host(\`whoami.example.com\`)" \
  --label "traefik.http.routers.whoami.entrypoints=websecure" \
  --label "traefik.http.routers.whoami.tls.certresolver=letsencrypt" \
  traefik/whoami

Or with file-based configuration:

# Create dynamic configuration
sudo nano /etc/traefik/dynamic/whoami.yml

Add:

http:
  routers:
    my-app:
      rule: "Host(`app.example.com`)"
      service: my-app-service
      entryPoints:
        - websecure
      tls:
        certResolver: letsencrypt

  services:
    my-app-service:
      loadBalancer:
        servers:
          - url: "http://192.168.1.10:8080"
          - url: "http://192.168.1.11:8080"
        healthCheck:
          path: /health
          interval: 30s

Your app is now accessible with automatic SSL! ๐Ÿ”’

๐Ÿ”’ Step 5: Advanced Features - Power User Mode!

Letโ€™s explore Traefikโ€™s advanced capabilities! ๐Ÿ’ช

Middleware for Request Modification:

# Rate limiting middleware
http:
  middlewares:
    rate-limit:
      rateLimit:
        average: 100
        burst: 50
        period: 1m

    # Security headers
    secure-headers:
      headers:
        frameDeny: true
        sslRedirect: true
        browserXssFilter: true
        contentTypeNosniff: true
        stsSeconds: 315360000
        stsIncludeSubdomains: true
        stsPreload: true

    # Basic authentication
    auth:
      basicAuth:
        users:
          - "admin:$2y$10$..."  # Generate with htpasswd

  routers:
    secure-app:
      rule: "Host(`secure.example.com`)"
      service: app
      middlewares:
        - rate-limit
        - secure-headers
        - auth

Load Balancing Strategies:

services:
  my-service:
    loadBalancer:
      servers:
        - url: "http://server1:80"
          weight: 3  # Gets 3x more traffic
        - url: "http://server2:80"
          weight: 1
      sticky:
        cookie:
          name: server_id
          httpOnly: true
          secure: true
      healthCheck:
        path: /health
        interval: 10s
        timeout: 3s

Circuit Breaker:

services:
  protected-service:
    loadBalancer:
      servers:
        - url: "http://backend:80"
    circuitBreaker:
      expression: "LatencyAtQuantileMS(50.0) > 100"

๐Ÿ“Š Step 6: Monitoring and Metrics - Know Your Traffic!

Enable Prometheus metrics:

# In traefik.yml
metrics:
  prometheus:
    addEntryPointsLabels: true
    addServicesLabels: true
    buckets:
      - 0.1
      - 0.3
      - 1.2
      - 5.0

ping:
  entryPoint: web

Configure firewall:

# Open necessary ports
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

Access dashboard at http://your-server:8080/dashboard/ ๐Ÿ“Š

๐ŸŽฎ Quick Examples

Example 1: Multiple Domains, One Server

Route different domains to different services:

http:
  routers:
    blog:
      rule: "Host(`blog.example.com`)"
      service: blog-service
      tls:
        certResolver: letsencrypt

    api:
      rule: "Host(`api.example.com`)"
      service: api-service
      tls:
        certResolver: letsencrypt

    shop:
      rule: "Host(`shop.example.com`)"
      service: shop-service
      tls:
        certResolver: letsencrypt

  services:
    blog-service:
      loadBalancer:
        servers:
          - url: "http://localhost:3000"
    
    api-service:
      loadBalancer:
        servers:
          - url: "http://localhost:4000"
    
    shop-service:
      loadBalancer:
        servers:
          - url: "http://localhost:5000"

Example 2: Path-Based Routing

Route by URL path:

http:
  routers:
    api-v1:
      rule: "Host(`api.example.com`) && PathPrefix(`/v1`)"
      service: api-v1

    api-v2:
      rule: "Host(`api.example.com`) && PathPrefix(`/v2`)"
      service: api-v2

Example 3: Kubernetes Integration

Use Traefik with K8s:

# IngressRoute CRD
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: my-app
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`app.example.com`)
      kind: Rule
      services:
        - name: my-app-service
          port: 80
  tls:
    certResolver: letsencrypt

๐Ÿšจ Fix Common Problems

Problem 1: SSL Certificate Not Working

Symptom: HTTPS shows certificate error ๐Ÿ”’

Fix:

# Check certificate resolver
docker logs traefik | grep acme

# Verify DNS points to server
nslookup your-domain.com

# Check acme.json permissions
ls -la /var/lib/traefik/acme.json
# Should be 600

# Use staging server for testing
# Add to traefik.yml:
# caServer: https://acme-staging-v02.api.letsencrypt.org/directory

Problem 2: Service Not Accessible

Symptom: 404 or connection refused ๐Ÿšซ

Fix:

# Check if service is detected
curl http://localhost:8080/api/http/routers

# Verify Docker labels
docker inspect your-container | grep -i traefik

# Check network connectivity
docker network inspect traefik-net

# View Traefik logs
docker logs traefik -f

Problem 3: Dashboard Not Loading

Symptom: Canโ€™t access Traefik dashboard ๐Ÿ“Š

Fix:

# Verify dashboard is enabled
grep -i dashboard /etc/traefik/traefik.yml

# Check if port is open
sudo netstat -tlnp | grep 8080

# Access locally first
curl http://localhost:8080/api/rawdata

# Check firewall
sudo firewall-cmd --list-ports

๐Ÿ“‹ Simple Commands Summary

CommandWhat It DoesWhen to Use
traefik versionCheck versionVerify install
docker logs traefikView logsTroubleshooting
curl /api/http/routersList routersCheck routes
curl /api/http/servicesList servicesCheck backends
docker network lsList networksCheck Docker
systemctl status traefikService statusHealth check
curl /metricsPrometheus metricsMonitoring
curl /pingHealth endpointLiveness check
docker-compose restartRestart TraefikApply changes
htpasswd -nb user passGenerate authSecurity

๐Ÿ’ก Tips for Success

๐Ÿš€ Performance Optimization

Make Traefik lightning fast:

# Enable HTTP/2 and HTTP/3
entryPoints:
  websecure:
    address: ":443"
    http2:
      maxConcurrentStreams: 250
    http3:
      advertisedPort: 443

# Compression middleware
http:
  middlewares:
    compress:
      compress:
        excludedContentTypes:
          - text/event-stream

๐Ÿ”’ Security Best Practices

Keep Traefik secure:

  1. Use strong authentication - Protect dashboard! ๐Ÿ”
  2. Enable rate limiting - Prevent DDoS! ๐Ÿ›ก๏ธ
  3. Security headers - Add all recommended headers! ๐Ÿ“‹
  4. Regular updates - Keep Traefik current! ๐Ÿ†•
  5. Minimal exposure - Donโ€™t expose Docker socket! ๐Ÿณ
# Security middleware chain
middlewares:
  security-chain:
    chain:
      middlewares:
        - rate-limit
        - secure-headers
        - auth

๐Ÿ“ˆ Monitoring Excellence

Track everything:

# Prometheus + Grafana
docker run -d \
  --name prometheus \
  --network traefik-net \
  -v ./prometheus.yml:/etc/prometheus/prometheus.yml \
  prom/prometheus

# Import Traefik dashboard ID: 4475

๐Ÿ† What You Learned

Youโ€™re now a Traefik expert! ๐ŸŽ“ Youโ€™ve successfully:

  • โœ… Installed Traefik on AlmaLinux
  • โœ… Configured automatic routing
  • โœ… Set up SSL certificates
  • โœ… Integrated with Docker
  • โœ… Created load balancing
  • โœ… Implemented middleware
  • โœ… Mastered monitoring

Your traffic management is cloud-native! ๐ŸŒ

๐ŸŽฏ Why This Matters

Traefik gives you modern traffic powers! With your reverse proxy, you can:

  • ๐Ÿš€ Deploy instantly - No manual configuration!
  • ๐Ÿ”’ Secure automatically - Free SSL everywhere!
  • โš–๏ธ Scale effortlessly - Load balance anything!
  • ๐ŸŽฏ Route intelligently - Complex rules made simple!
  • ๐Ÿ“Š Monitor everything - Real-time visibility!

Youโ€™re not just routing traffic - youโ€™re orchestrating it with modern, cloud-native patterns! Your infrastructure now adapts automatically to changes! ๐ŸŒŸ

Keep routing, keep balancing, and remember - with Traefik, your traffic flows like water! โญ

May your routes be fast and your certificates be valid! ๐Ÿš€๐Ÿ”’๐Ÿ™Œ