How to Proxy Your Hugo Site with Traefik on Alpine Linux
To set up Traefik to proxy your Hugo site running on an Alpine VM with the IP address 192.168.0.155, you’ll need to configure Traefik rules. Here’s how to do it:
Step 1: Install Docker and Docker Compose
If not already installed, use the following commands to install Docker and Docker Compose:
sudo apk add docker
sudo apk add docker-compose
Step 2: Create a Docker Compose File
Create a docker-compose.yml file for Traefik on your VM where Traefik is running. Here is an example configuration:
version: '3'
services:
  traefik:
    image: traefik:v2.5
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.file.directory=/etc/traefik/dynamic"
      - "--entrypoints.web.address=:80"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "./traefik.yml:/etc/traefik/traefik.yml"
      - "./dynamic:/etc/traefik/dynamic"
Step 3: Create Traefik Configuration Files
Create a file named traefik.yml with the following content:
api:
  dashboard: true
entryPoints:
  web:
    address: ":80"
providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
  file:
    directory: "/etc/traefik/dynamic"
    watch: true
Create a directory named dynamic and inside it, create a file named dynamic.yml with the following content:
http:
  routers:
    hugo-router:
      rule: "Host(`your_domain.com`)"
      service: hugo-service
  services:
    hugo-service:
      loadBalancer:
        servers:
          - url: "http://192.168.0.155:1313"
Replace your_domain.com with your actual domain.
Step 4: Deploy with Docker Compose
Navigate to the directory containing your docker-compose.yml file and run:
sudo docker-compose up -d
Step 5: Configure DNS Settings
Update your DNS settings to point your domain to the VM’s IP address where Traefik is running. This typically involves setting up an A record or CNAME record with your domain registrar.
Step 6: Access Your Hugo Site
Once everything is set up, you should be able to access your Hugo site externally by navigating to your domain (e.g., http://your_domain.com).
This setup will allow Traefik to proxy requests to your Hugo site running on the Alpine VM. 🌐🚀
Chuck Norris Joke:
When Chuck Norris proxies a site with Traefik, the traffic doesn’t just follow—it salutes and marches in perfect formation.