feat(docker): nginx static-export image + Dokploy compose with env-driven PORT/origin
- 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
This commit is contained in:
1 parent
f6b5ba112b
commit
ae34597847
44 files changed
+416
-136
No files matched your search
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# แทน origin ที่อบไว้ในไฟล์ static (canonical / og:url / JSON-LD / sitemap / robots / ai.txt)
|
||||
# ใช้เมื่อ PUBLIC_ORIGIN ต่างจาก BAKED_ORIGIN เช่น deploy ขึ้นโดเมนใหม่หรือ preview หลายโดเมน
|
||||
# ไม่ตั้งค่า = ใช้ origin ที่อบมาแล้ว (ไม่มีอะไรเปลี่ยน)
|
||||
set -eu
|
||||
|
||||
PUBLIC_ORIGIN="${PUBLIC_ORIGIN:-}"
|
||||
BAKED_ORIGIN="${BAKED_ORIGIN:-}"
|
||||
|
||||
if [ -z "$PUBLIC_ORIGIN" ] || [ "$PUBLIC_ORIGIN" = "$BAKED_ORIGIN" ]; then
|
||||
echo "origin: ใช้ค่าที่อบมา ($BAKED_ORIGIN) — ไม่ต้องแทนที่"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
DOC_ROOT=/usr/share/nginx/html
|
||||
changed=0
|
||||
for f in $(find "$DOC_ROOT" -type f \( -name '*.html' -o -name '*.xml' -o -name '*.txt' \)); do
|
||||
if grep -qF "$BAKED_ORIGIN" "$f"; then
|
||||
sed -i "s|${BAKED_ORIGIN}|${PUBLIC_ORIGIN}|g" "$f"
|
||||
changed=$((changed + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "origin: แทนที่ ${BAKED_ORIGIN} → ${PUBLIC_ORIGIN} ใน ${changed} ไฟล์"
|
||||
@@ -0,0 +1,84 @@
|
||||
# server ของ static export — ไฟล์ config นี้เป็น template
|
||||
# nginx official entrypoint จะแทนค่า env (${PORT}, ${PUBLIC_ORIGIN}) ให้ตอนสตาร์ท
|
||||
# ตัวแปรของ nginx ($uri, $host, ...) ไม่ถูกแทน เพราะ envsubst จำกัดเฉพาะชื่อ env ที่มีจริง
|
||||
|
||||
server {
|
||||
listen ${PORT};
|
||||
listen [::]:${PORT};
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
charset utf-8;
|
||||
server_tokens off;
|
||||
|
||||
# ── http → https ──────────────────────────────────────────────────────
|
||||
# Dokploy/Traefik ต่อเข้ามาเป็น http ภายในแล้วแนบ X-Forwarded-Proto มาให้
|
||||
# ถ้าเป็น "http" = ผู้ใช้เข้ามาทาง http → 301 ไป https เสมอ (path + query เดิม)
|
||||
if ($http_x_forwarded_proto = "http") {
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
# ── response headers (ชุดเดียวกับทุก location — ดู docker/security-headers.conf)
|
||||
include snippets/security-headers.conf;
|
||||
|
||||
# ── compression ──────────────────────────────────────────────────────
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 6;
|
||||
gzip_min_length 512;
|
||||
gzip_proxied any;
|
||||
gzip_types text/plain text/css text/xml application/javascript application/json
|
||||
application/xml application/manifest+json image/svg+xml;
|
||||
|
||||
# ── healthcheck (ไม่ถูก redirect, ไม่ลง log) ──────────────────────────
|
||||
location = /healthz {
|
||||
access_log off;
|
||||
default_type text/plain;
|
||||
include snippets/security-headers.conf;
|
||||
return 200 "ok\n";
|
||||
}
|
||||
|
||||
# ── service worker / manifest: ห้าม cache ยาว (ต้องได้ตัวใหม่ทันที) ──
|
||||
location = /sw.js {
|
||||
add_header Cache-Control "no-cache" always;
|
||||
include snippets/security-headers.conf;
|
||||
try_files $uri =404;
|
||||
}
|
||||
location = /manifest.json {
|
||||
add_header Cache-Control "no-cache" always;
|
||||
include snippets/security-headers.conf;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# ── asset ที่ชื่อมี hash: cache ได้ยาวและ immutable ────────────────────
|
||||
location /assets/ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable" always;
|
||||
include snippets/security-headers.conf;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# ── รูป/ฟอนต์: cache 30 วัน ───────────────────────────────────────────
|
||||
location ~* \.(?:png|jpe?g|webp|avif|gif|svg|ico|woff2?|ttf)$ {
|
||||
add_header Cache-Control "public, max-age=2592000" always;
|
||||
include snippets/security-headers.conf;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# ── หน้าเว็บ: clean URL ───────────────────────────────────────────────
|
||||
# /cinema/<slug> → /cinema/<slug>/index.html โดย "ไม่" redirect ไปเติม /
|
||||
# (canonical ที่อบไว้ไม่มี trailing slash — ต้องตรงกัน)
|
||||
location / {
|
||||
add_header Cache-Control "no-cache" always;
|
||||
include snippets/security-headers.conf;
|
||||
try_files $uri $uri/index.html $uri/ =404;
|
||||
}
|
||||
|
||||
# ── 404 ──────────────────────────────────────────────────────────────
|
||||
error_page 404 /404.html;
|
||||
location = /404.html {
|
||||
internal;
|
||||
include snippets/security-headers.conf;
|
||||
add_header Cache-Control "no-store" always;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# ชุด header ความปลอดภัย — ใช้ `include snippets/security-headers.conf;` ในทุก location
|
||||
# (จำเป็นเพราะ nginx ทิ้ง add_header ของ parent ทันทีที่ location นิยาม add_header เอง)
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
|
||||
Reference in new issue
Block a user