Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

First Website Deployment

3.1 Create Website Directory

mkdir -p /opt/docker/websites/vps-test/html
cd /opt/docker/websites/vps-test

3.2 Create Test HTML Page

File: /opt/docker/websites/vps-test/html/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>VPS Test Site</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .container {
            text-align: center;
        }
        h1 { font-size: 3em; margin: 0; }
        p { font-size: 1.5em; }
        .success { color: #4ade80; }
    </style>
</head>
<body>
    <div class="container">
        <h1>🎉 Success!</h1>
        <p>Traefik + SSL is working perfectly!</p>
        <p class="success">✓ Automatic HTTPS</p>
        <p class="success">✓ Reverse Proxy Active</p>
    </div>
</body>
</html>

3.3 Create Website Docker Compose

File: /opt/docker/websites/vps-test/docker-compose.yml

version: '3.8'

services:
  vps-test:
    image: nginx:alpine
    container_name: vps-test
    restart: unless-stopped
    networks:
      - web
    volumes:
      - ./html:/usr/share/nginx/html:ro
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.vpstest.rule=Host(`vps-test.mydomain.com`)"
      - "traefik.http.routers.vpstest.entrypoints=websecure"
      - "traefik.http.routers.vpstest.tls.certresolver=letsencrypt"
      - "traefik.http.services.vpstest.loadbalancer.server.port=80"

networks:
  web:
    external: true

Label Breakdown:

  • traefik.enable=true: Tell Traefik to route this container
  • Host(\vps-test.mydomain.com`)`: Match this domain
  • websecure: Use HTTPS (port 443)
  • letsencrypt: Get SSL certificate automatically
  • port=80: Nginx listens on port 80 internally

3.4 Deploy Test Site

cd /opt/docker/websites/vps-test
docker compose up -d

# Check logs
docker compose logs -f

3.5 Verify Website

  1. Open browser: https://vps-test.mydomain.com
  2. Should see:
    • ✅ Valid SSL certificate (green padlock)
    • ✅ No certificate warnings
    • ✅ Test page displaying correctly