- Dockerfile: nginx:1.27-alpine serving the exported site, PORT from env, /healthz healthcheck, origin rewrite hook in docker-entrypoint.d - docker/default.conf.template: envsubst PORT, clean URLs without trailing-slash redirect, long cache for hashed assets, no-cache for HTML/sw.js/manifest, 301 http->https via X-Forwarded-Proto, gzip - docker/security-headers.conf: single include so add_header survives per location - docker-compose.yml (Dokploy, no host ports) + docker-compose.override.yml (local) - bake canonical/OG/sitemap/robots origin to https://alterflixhub.hobbypj.com (was the export-time 127.0.0.1:8090), overridable via PUBLIC_ORIGIN - docs/deploy-dokploy.md
4.7 KiB
4.7 KiB
Deploy AlterFlixHub (static export) ด้วย Docker / Dokploy
repo นี้เก็บ ไฟล์ static export ที่ราก repo — ไม่มี build step, image คือ nginx + ไฟล์เว็บ
ไฟล์ที่เกี่ยวข้อง
| ไฟล์ | หน้าที่ |
|---|---|
Dockerfile |
nginx:1.27-alpine + ไฟล์เว็บ → /usr/share/nginx/html · healthcheck /healthz |
docker/default.conf.template |
nginx config (template) — clean URL, cache, redirect http→https |
docker/security-headers.conf |
header ความปลอดภัยชุดเดียว ใช้ include ทุก location |
docker/30-origin.sh |
ตอน start: แทน origin ใน canonical/OG/JSON-LD/sitemap/robots ตาม PUBLIC_ORIGIN |
docker-compose.yml |
base สำหรับ Dokploy — ไม่ publish พอร์ตออก host (Traefik ต่อผ่าน network) |
docker-compose.override.yml |
สำหรับรันในเครื่อง — แมป 127.0.0.1:${HOST_PORT} |
.dockerignore |
ตัด .git, compose, docs, ไฟล์สำรองออกจาก build context |
env
| ตัวแปร | ค่า default | ใช้ทำอะไร |
|---|---|---|
PORT |
30004 |
พอร์ตที่ nginx ฟังในคอนเทนเนอร์ (ตั้งใน Dokploy = 30004) |
PUBLIC_ORIGIN |
https://alterflixhub.hobbypj.com |
origin ที่เขียนลง canonical / og:url / JSON-LD / sitemap / robots |
BAKED_ORIGIN |
https://alterflixhub.hobbypj.com |
origin ที่อบมากับไฟล์ — ต้นทางของการแทนที่ (ปกติไม่ต้องแตะ) |
HOST_PORT |
30004 |
(เฉพาะในเครื่อง) พอร์ตที่แมปออก host |
TZ |
Asia/Bangkok |
timezone ของ log |
เปลี่ยนโดเมน = ตั้ง PUBLIC_ORIGIN=https://โดเมนใหม่ แล้ว redeploy (สคริปต์แทนให้เองตอน start, 36 ไฟล์)
หรือแก้ BAKED_ORIGIN ให้ตรงกับที่อบไว้ถ้าเคยอบจากโดเมนอื่น
http → https
nginx ดู X-Forwarded-Proto ที่ Traefik/Dokploy ส่งมา — ถ้าเป็น http จะตอบ 301 ไป https://$host$request_uri (คง path + query)
/healthz เป็นข้อยกเว้น (healthcheck วิ่ง http ภายในได้) · เปิด HSTS max-age=15552000 ให้แล้ว
ตั้งใน Dokploy
- สร้าง Application → Provider Docker / Build type Dockerfile (path
./Dockerfile), Compose file./docker-compose.yml - Environment:
PORT=30004(PUBLIC_ORIGINตั้งเมื่อโดเมนไม่ใช่ค่า default) - Domains:
alterflixhub.hobbypj.com→ container port 30004, เปิด HTTPS (Let's Encrypt) + redirect - Deploy — healthcheck ต้องผ่าน (
wget -qO- http://127.0.0.1:$PORT/healthz)
Dokploy เรียก
docker compose -f ./docker-compose.yml→ ไม่โหลดdocker-compose.override.yml(พอร์ตบน server จึงไม่ชน)
รันในเครื่อง (preview)
docker compose up -d --build # http://127.0.0.1:30004/
docker compose logs -f web
docker compose down
PORT=31004 HOST_PORT=31004 PUBLIC_ORIGIN=https://staging.example.com docker compose up -d # ทดสอบ env อื่น
Cache ที่ตั้งไว้
| path | Cache-Control |
|---|---|
/assets/* (ชื่อมี hash) |
public, max-age=31536000, immutable |
| รูป/ฟอนต์ | public, max-age=2592000 |
| HTML ทุกหน้า | no-cache (ต้อง revalidate) |
sw.js, manifest.json |
no-cache |
sw.js เป็น cache-first สำหรับ /assets/* → ทุกครั้งที่แก้ CSS/JS ในไฟล์ export ต้อง bump const VERSION ใน sw.js
แก้โดเมน/ค่าในไฟล์ export
- canonical/OG/sitemap/robots: ตั้ง
PUBLIC_ORIGIN(runtime) หรือแทนสตริงในไฟล์ตอน publish - อย่าแก้ attribute ใน HTML ด้วยมือหลังจากที่ไฟล์ถูก hydrate แล้ว — จะ hydration mismatch
- หน้า
/cinema/<slug>ไม่มี trailing slash (canonical เป็นแบบนั้น) — nginxtry_files $uri $uri/index.htmlเสิร์ฟตรง ไม่ redirect