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).
This commit is contained in:
Bkk1234 committed 2026-11-22 23:52:54 +07:00
1 parent 8dca22622a
commit 3ebfcfea75
1 file changed
+26 -24
+26 -24
View File
@@ -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 <file> dokploy_dokploy-traefik.1.<hash>:/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 <container-name>
# ค่าที่ใช้จริงบน 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.<name>.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