From 3ebfcfea751dd04219d8d30ae23208bfa7327e14 Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Sun, 22 Nov 2026 23:52:54 +0700 Subject: [PATCH] docs(traefik): match production config (priority 200, real container, shared middleware) Record the values verified on the server: container alterflixhub-compose-doefaz-web-1:30004 on dokploy-network, redirect-to-https from middlewares.yml, and priority 200 to win over the Dokploy docker-provider routers whose label still hardcodes server.port=8080 (the 502 cause). --- docker/traefik-dynamic.example.yml | 50 ++++++++++++++++-------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/docker/traefik-dynamic.example.yml b/docker/traefik-dynamic.example.yml index 7003b48..67ec1c9 100644 --- a/docker/traefik-dynamic.example.yml +++ b/docker/traefik-dynamic.example.yml @@ -1,46 +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 dynamic config (File Provider) สำหรับ alterflixhub.hobbypj.com +# วางที่ /etc/dokploy/traefik/dynamic/alterflixhub-hobbypj.yml +# - Dokploy UI: Web Server → Traefik File System → dynamic/ → New File +# - หรือ SSH: scp แล้ว `docker cp dokploy_dokploy-traefik.1.:/etc/dokploy/traefik/dynamic/` # 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 +# ค่าที่ใช้จริงบน server +# container : alterflixhub-compose-doefaz-web-1 (image alterflixhub-web:latest, nginx, PORT=30004) +# network : dokploy-network (Traefik เป็น swarm service อยู่บน network นี้) +# middleware : redirect-to-https (ประกาศใน middlewares.yml ของเครื่องนั้นอยู่แล้ว) +# +# ทำไมต้องมี priority: 200 +# Dokploy สร้าง router จาก docker labels ให้โดเมนเดียวกันด้วย โดย label +# traefik.http.services..loadbalancer.server.port ถูก hardcode เป็น 8080 +# แต่ nginx ฟัง 30004 → router ชุดนั้นตอบ 502 และ rule ยาวเท่ากัน (Host เดียวกัน) +# Traefik จึงเลือกไม่แน่นอน → ต้องประกาศ priority ให้ router ในไฟล์นี้ชนะ http: routers: - # 1) http (พอร์ต 80) → 301 ไป https - alterflixhub-web: - rule: "Host(`alterflixhub.hobbypj.com`)" + # 1) http (พอร์ต 80) → redirect ไป https (middleware กลางของเครื่อง) + alterflixhub-hobbypj-http-router: + rule: Host(`alterflixhub.hobbypj.com`) + service: alterflixhub-service entryPoints: - web + priority: 200 middlewares: - - alterflixhub-redirect-https - service: alterflixhub-service + - redirect-to-https # 2) https (พอร์ต 443) → เสิร์ฟเว็บจริง + ขอ cert จาก letsencrypt - alterflixhub-websecure: - rule: "Host(`alterflixhub.hobbypj.com`)" + alterflixhub-hobbypj-https-router: + rule: Host(`alterflixhub.hobbypj.com`) + service: alterflixhub-service entryPoints: - websecure - service: alterflixhub-service + priority: 200 tls: certResolver: letsencrypt - middlewares: - alterflixhub-redirect-https: - redirectScheme: - scheme: https - permanent: true - services: alterflixhub-service: loadBalancer: - # ชื่อ container:พอร์ต *ใน* คอนเทนเนอร์ (ไม่ใช่พอร์ตที่ map ออก host) + # ชื่อ container : พอร์ต *ใน* คอนเทนเนอร์ (ไม่ใช่พอร์ตที่ map ออก host) servers: - - url: "http://web-alterflixhub-web-1:30004" + - url: http://alterflixhub-compose-doefaz-web-1:30004 passHostHeader: true healthCheck: path: /healthz