main.agent-native-app-main is a scroll container (overflow-y:auto + overscroll-contain) whose content equals its own height, so it swallowed the wheel and the document never scrolled; the site wrapper's overflow-x:hidden also made its overflow-y compute to auto. Neutralise both scrollers so the document is the only scroller (overflow-x:clip keeps horizontal clipping). Cache safety: the patched CSS kept its old hashed filename, and nginx served /assets/* as immutable for a year, so visitors with the earlier CSS could never receive the fix. Renamed the stylesheet to a content hash and updated 34 HTML references, switched /assets/ to no-cache (revalidate, 304), bumped sw.js VERSION to v2.1.2. docs/deploy-dokploy.md updated.
73 lines
5.4 KiB
Markdown
73 lines
5.4 KiB
Markdown
# 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
|
|
|
|
1. สร้าง Application → Provider **Docker** / Build type **Dockerfile** (path `./Dockerfile`), Compose file `./docker-compose.yml`
|
|
2. Environment: `PORT=30004` (`PUBLIC_ORIGIN` ตั้งเมื่อโดเมนไม่ใช่ค่า default)
|
|
3. Domains: `alterflixhub.hobbypj.com` → container port **30004**, เปิด **HTTPS** (Let's Encrypt) + redirect
|
|
4. Deploy — healthcheck ต้องผ่าน (`wget -qO- http://127.0.0.1:$PORT/healthz`)
|
|
|
|
> Dokploy เรียก `docker compose -f ./docker-compose.yml` → ไม่โหลด `docker-compose.override.yml` (พอร์ตบน server จึงไม่ชน)
|
|
|
|
## รันในเครื่อง (preview)
|
|
|
|
```bash
|
|
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/*` (JS/CSS) | `no-cache` — แคชได้แต่ revalidate ทุกครั้ง |
|
|
| รูป/ฟอนต์ | `public, max-age=2592000` |
|
|
| HTML ทุกหน้า | `no-cache` (ต้อง revalidate) |
|
|
| `sw.js`, `manifest.json` | `no-cache` |
|
|
|
|
> **ทำไม `/assets/` ไม่ใช้ `immutable`:** ในโหมด publish static export เราแก้ไฟล์ CSS/JS ด้วยมือโดยชื่อเดิมบ่อย
|
|
> ถ้า cache ยาว เครื่องที่เคยโหลดจะค้างไฟล์เก่าเป็นปี (เคสจริง: fix scroll/wheel ไม่ถึงผู้ใช้)
|
|
> เวลาแก้ CSS/JS ให้ **เปลี่ยนชื่อไฟล์เป็น hash ใหม่ + แก้ `<link>` ใน HTML** ด้วย แล้ว bump `VERSION` ใน `sw.js`
|
|
|
|
`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 เป็นแบบนั้น) — nginx `try_files $uri $uri/index.html` เสิร์ฟตรง ไม่ redirect
|