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 # Traefik dynamic config (File Provider) สำหรับ alterflixhub.hobbypj.com
# วางไฟล์นี้ใน /etc/dokploy/traefik/dynamic/ ผ่าน Dokploy → Web Server → Traefik File System # วางที่ /etc/dokploy/traefik/dynamic/alterflixhub-hobbypj.yml
# เช่นตั้งชื่อไฟล์: alterflixhub-hobbypj-com.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 # Traefik watch โฟลเดอร์นี้อยู่แล้ว → save แล้วมีผลทันที ไม่ต้อง restart
# #
# ก่อนใช้ต้องมั่นใจ 2 อย่าง # ค่าที่ใช้จริงบน server
# 1) DNS alterflixhub.hobbypj.com ชี้มาที่ IP ของเครื่องที่รัน Dokploy (สำหรับ Let's Encrypt HTTP-01 ต้องเปิดพอร์ต 80) # container : alterflixhub-compose-doefaz-web-1 (image alterflixhub-web:latest, nginx, PORT=30004)
# 2) container ของเว็บอยู่ใน network เดียวกับ Traefik (dokploy-network) และ Traefik ต่อถึงได้ที่ "ชื่อ container:30004" # network : dokploy-network (Traefik เป็น swarm service อยู่บน network นี้)
# หาชื่อจริงด้วย: docker ps --format '{{.Names}}\t{{.Ports}}' | grep alterflix # middleware : redirect-to-https (ประกาศใน middlewares.yml ของเครื่องนั้นอยู่แล้ว)
# ถ้ายังไม่อยู่ใน network: docker network connect dokploy-network <container-name> #
# ทำไมต้องมี 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: http:
routers: routers:
# 1) http (พอร์ต 80) → 301 ไป https # 1) http (พอร์ต 80) → redirect ไป https (middleware กลางของเครื่อง)
alterflixhub-web: alterflixhub-hobbypj-http-router:
rule: "Host(`alterflixhub.hobbypj.com`)" rule: Host(`alterflixhub.hobbypj.com`)
service: alterflixhub-service
entryPoints: entryPoints:
- web - web
priority: 200
middlewares: middlewares:
- alterflixhub-redirect-https - redirect-to-https
service: alterflixhub-service
# 2) https (พอร์ต 443) → เสิร์ฟเว็บจริง + ขอ cert จาก letsencrypt # 2) https (พอร์ต 443) → เสิร์ฟเว็บจริง + ขอ cert จาก letsencrypt
alterflixhub-websecure: alterflixhub-hobbypj-https-router:
rule: "Host(`alterflixhub.hobbypj.com`)" rule: Host(`alterflixhub.hobbypj.com`)
service: alterflixhub-service
entryPoints: entryPoints:
- websecure - websecure
service: alterflixhub-service priority: 200
tls: tls:
certResolver: letsencrypt certResolver: letsencrypt
middlewares:
alterflixhub-redirect-https:
redirectScheme:
scheme: https
permanent: true
services: services:
alterflixhub-service: alterflixhub-service:
loadBalancer: loadBalancer:
# ชื่อ container:พอร์ต *ใน* คอนเทนเนอร์ (ไม่ใช่พอร์ตที่ map ออก host) # ชื่อ container : พอร์ต *ใน* คอนเทนเนอร์ (ไม่ใช่พอร์ตที่ map ออก host)
servers: servers:
- url: "http://web-alterflixhub-web-1:30004" - url: http://alterflixhub-compose-doefaz-web-1:30004
passHostHeader: true passHostHeader: true
healthCheck: healthCheck:
path: /healthz path: /healthz