From 8dca22622a9d02050b0ed374c61b0b20d3faadf4 Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Sun, 22 Nov 2026 22:59:04 +0700 Subject: [PATCH] docs(traefik): add dynamic file-provider config for alterflixhub.hobbypj.com Adds docker/traefik-dynamic.example.yml (web -> 301 https, websecure with letsencrypt resolver, loadBalancer to container:30004 with /healthz check) and a deploy-dokploy.md section covering the Dokploy Traefik File System steps, the DNS/dokploy-network prerequisites, and post-save verification. --- .dockerignore | 1 + docker/traefik-dynamic.example.yml | 48 ++++++++++++++++++++++++++ docs/deploy-dokploy.md | 54 ++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 docker/traefik-dynamic.example.yml diff --git a/.dockerignore b/.dockerignore index bd5fa8e..7bfcf52 100644 --- a/.dockerignore +++ b/.dockerignore @@ -23,6 +23,7 @@ coverage *.orig *.tmp probe-* +docker/traefik-dynamic.example.yml .DS_Store Thumbs.db desktop.ini diff --git a/docker/traefik-dynamic.example.yml b/docker/traefik-dynamic.example.yml new file mode 100644 index 0000000..7003b48 --- /dev/null +++ b/docker/traefik-dynamic.example.yml @@ -0,0 +1,48 @@ +# ตัวอย่าง Traefik dynamic config (File Provider) สำหรับ alterflixhub.hobbypj.com +# วางไฟล์นี้ใน /etc/dokploy/traefik/dynamic/ ผ่าน Dokploy → Web Server → Traefik File System +# เช่นตั้งชื่อไฟล์: alterflixhub-hobbypj-com.yml +# Traefik watch โฟลเดอร์นี้อยู่แล้ว → save แล้วมีผลทันที ไม่ต้อง restart +# +# ก่อนใช้ต้องมั่นใจ 2 อย่าง +# 1) DNS alterflixhub.hobbypj.com ชี้มาที่ IP ของเครื่องที่รัน Dokploy (สำหรับ Let's Encrypt HTTP-01 ต้องเปิดพอร์ต 80) +# 2) container ของเว็บอยู่ใน network เดียวกับ Traefik (dokploy-network) และ Traefik ต่อถึงได้ที่ "ชื่อ container:30004" +# หาชื่อจริงด้วย: docker ps --format '{{.Names}}\t{{.Ports}}' | grep alterflix +# ถ้ายังไม่อยู่ใน network: docker network connect dokploy-network + +http: + routers: + # 1) http (พอร์ต 80) → 301 ไป https + alterflixhub-web: + rule: "Host(`alterflixhub.hobbypj.com`)" + entryPoints: + - web + middlewares: + - alterflixhub-redirect-https + service: alterflixhub-service + + # 2) https (พอร์ต 443) → เสิร์ฟเว็บจริง + ขอ cert จาก letsencrypt + alterflixhub-websecure: + rule: "Host(`alterflixhub.hobbypj.com`)" + entryPoints: + - websecure + service: alterflixhub-service + tls: + certResolver: letsencrypt + + middlewares: + alterflixhub-redirect-https: + redirectScheme: + scheme: https + permanent: true + + services: + alterflixhub-service: + loadBalancer: + # ชื่อ container:พอร์ต *ใน* คอนเทนเนอร์ (ไม่ใช่พอร์ตที่ map ออก host) + servers: + - url: "http://web-alterflixhub-web-1:30004" + passHostHeader: true + healthCheck: + path: /healthz + interval: 30s + timeout: 3s diff --git a/docs/deploy-dokploy.md b/docs/deploy-dokploy.md index d2eb590..7035eb4 100644 --- a/docs/deploy-dokploy.md +++ b/docs/deploy-dokploy.md @@ -41,6 +41,60 @@ nginx ดู `X-Forwarded-Proto` ที่ Traefik/Dokploy ส่งมา — > Dokploy เรียก `docker compose -f ./docker-compose.yml` → ไม่โหลด `docker-compose.override.yml` (พอร์ตบน server จึงไม่ชน) +## เพิ่มโดเมนผ่าน Traefik File System (Dokploy) + +Dokploy → เมนูซ้าย **Web Server → Traefik File System** (URL `/dashboard/traefik`) → โฟลเดอร์ `dynamic/` → **New File** +ตั้งชื่อ `alterflixhub-hobbypj-com.yml` แล้ววางเนื้อหาจาก [`docker/traefik-dynamic.example.yml`](../docker/traefik-dynamic.example.yml) (แก้ชื่อ container ให้ตรงจริง) + +```yaml +http: + routers: + alterflixhub-web: + rule: "Host(`alterflixhub.hobbypj.com`)" + entryPoints: [web] + middlewares: [alterflixhub-redirect-https] + service: alterflixhub-service + alterflixhub-websecure: + rule: "Host(`alterflixhub.hobbypj.com`)" + entryPoints: [websecure] + service: alterflixhub-service + tls: + certResolver: letsencrypt + middlewares: + alterflixhub-redirect-https: + redirectScheme: {scheme: https, permanent: true} + services: + alterflixhub-service: + loadBalancer: + servers: + - url: "http://web-alterflixhub-web-1:30004" # ชื่อ container : พอร์ตในคอนเทนเนอร์ + passHostHeader: true + healthCheck: {path: /healthz, interval: 30s, timeout: 3s} +``` + +เงื่อนไขที่ต้องครบ ไม่งั้นได้ 404 / 502 + +1. **DNS** `alterflixhub.hobbypj.com` → IP เครื่องที่รัน Dokploy (พอร์ต 80 เปิด เพื่อ Let's Encrypt HTTP-01) +2. **Traefik ต่อถึง container ได้** — container ต้องอยู่ใน `dokploy-network` และชื่อต้องตรงกับ `url:` + - หาชื่อจริงบน server: `docker ps --format '{{.Names}}\t{{.Ports}}' | grep alterflix` + - ถ้ายังไม่เข้า network: `docker network connect dokploy-network ` + - ทางเลือกที่ยั่งยืนกว่า: ให้ compose ต่อ `dokploy-network` เอง (เพิ่ม `networks: [dokploy-network]` + `networks: dokploy-network: external: true`) แล้ว redeploy +3. **entrypoints ต้องมีจริง** — `web` = :80, `websecure` = :443 คือค่าที่ Dokploy สร้างให้ใน `traefik.yml` อยู่แล้ว (ห้ามลบ/เปลี่ยนชื่อ) + +ไฟล์ใน `dynamic/` ถูก watch → save แล้วมีผลทันที ไม่ต้อง restart Traefik + +ตรวจหลัง save + +```bash +curl -I https://alterflixhub.hobbypj.com/ # 200 +curl -I http://alterflixhub.hobbypj.com/cinema/kku-cinema # 301 → https +docker logs --tail=40 dokploy-traefik | grep -i -E 'alterflix|error' +``` + +> ทางที่ Dokploy ทำให้เอง: ใส่ domain ในแท็บ **Domains** ของ application (Dokploy เขียนไฟล์ dynamic ให้เอง +> — สำหรับ Compose app จะใช้ Traefik labels ซึ่งต้อง redeploy ก่อนมีผล) · ถ้าใช้ Files System ด้วยมือ +> ให้ลบ domain เดียวกันออกจากแท็บ Domains ก่อน ไม่งั้นจะได้ router ซ้ำกัน + ## รันในเครื่อง (preview) ```bash