Multi-site / Traefik
Hostinger Multi-site Platform
Biến một VPS thành nền tảng host nhiều website độc lập bằng Traefik, Docker Compose và GHCR.
Tổng quan kiến trúc
Một Traefik gateway chung route nhiều domain vào các Compose project tách biệt.
InternetNhiều domain
↓
Traefik80 / 443 · ACME
↓
Site AReact → NestJS → DB
Site BReact → NestJS → DB
Site CReact → NestJS → DB
Prerequisites
Cấu trúc trên VPS
/opt/
├── infrastructure/
│ ├── traefik/
│ └── monitoring/
├── sites/
│ ├── site-a/
│ │ ├── docker-compose.yml
│ │ ├── .env
│ │ └── scripts/
│ ├── site-b/
│ └── site-c/
└── backups/
├── site-a/
├── site-b/
└── site-c/
Các bước setup
1. Bootstrap platformTạo network
traefik-proxy và thư mục
infrastructure/sites/backups.
2. Start TraefikĐiền ACME email rồi chạy Compose trong
/opt/infrastructure/traefik.
3. Tạo site đầu tiênDùng script
create-site.sh với site slug, domain, GHCR owner và
repo name.
4. Điền .envDB password, JWT secret, image owner/repository và health URL.
5. Trỏ DNSA record của từng domain đều có thể trỏ về cùng VPS.
6. Push mainGitHub Actions build image, GHCR lưu image, VPS pull đúng Git SHA.
Bootstrap
sudo bash scripts/bootstrap-vps.sh sudo nano /opt/infrastructure/traefik/.env cd /opt/infrastructure/traefik docker compose up -d
Tạo site mới
sudo bash scripts/create-site.sh \ shop \ shop.example.com \ mycompany \ shop
Thêm site thứ hai
sudo bash scripts/create-site.sh \ crm \ crm.example.com \ mycompany \ crm
Kiểm tra
docker network inspect traefik-proxy
docker ps --format 'table {{.Names}}\t{{.Ports}}'
cd /opt/infrastructure/traefik
docker compose ps
docker compose logs -f traefik
cd /opt/sites/shop
docker compose ps
docker compose logs -f backend
Lỗi thường gặp
Domain vào Traefik nhưng 404
Kiểm tra labels router rule, network traefik-proxy, domain DNS và
service port label.
Let's Encrypt không cấp cert
Kiểm tra DNS đã về đúng IP, port 80/443 mở và Traefik ACME email/storage đúng.
Hai site conflict
Không dùng container_name giống nhau. Để Compose tự namespace theo
project.
VPS build quá tải
Chuyển build sang GitHub Actions + GHCR, VPS chỉ pull image.