Files
justice/www/html/Game/public/trycss/game-justic2/server/fix-404-realtimechat-game.sh
T
2026-05-27 04:30:21 +00:00

54 lines
2.6 KiB
Bash

#!/bin/bash
# ใช้รันบนเซิร์ฟเวอร์ (srv1361159) เพื่อตรวจและแก้ 404 realtimechat / Game
# รัน: sudo bash fix-404-realtimechat-game.sh
set -e
WWW=/var/www/html
NGINX_SITE=/etc/nginx/sites-enabled/srv1361159.hstgr.cloud
echo "=== 1. ตรวจว่ามีโฟลเดอร์และ index ==="
for dir in realtimechat Game; do
if [ -d "$WWW/$dir" ]; then
echo "[OK] $WWW/$dir มีอยู่"
if [ -f "$WWW/$dir/index.html" ]; then
echo " [OK] index.html มีอยู่"
elif [ -f "$WWW/$dir/public/index.html" ]; then
echo " [OK] public/index.html มีอยู่ (อาจต้องใช้ root ไปที่ public)"
else
echo " [!!] ไม่พบ index.html ใน $dir หรือ $dir/public"
fi
else
echo "[!!] ไม่มีโฟลเดอร์ $WWW/$dir"
fi
done
echo ""
echo "=== 2. ตรวจ Nginx config ==="
if [ -f "$NGINX_SITE" ]; then
echo "ไฟล์: $NGINX_SITE"
grep -n "realtimechat\|/Game\|location\|root\|alias\|proxy_pass" "$NGINX_SITE" || true
else
echo "ไม่พบ $NGINX_SITE (อาจใช้ default หรือชื่ออื่น)"
ls -la /etc/nginx/sites-enabled/
fi
echo ""
echo "=== 3. ตรวจ service Node ==="
systemctl is-active realtimechat 2>/dev/null || echo "realtimechat: ไม่ได้รันหรือไม่มี unit"
systemctl is-active game-zep 2>/dev/null || echo "game-zep: ไม่ได้รันหรือไม่มี unit"
echo ""
echo "=== 4. แนะนำแก้ 404 (เลือกทำตามกรณี) ==="
echo "ถ้า Nginx ใช้ proxy_pass ไปที่ Node (พอร์ต 3000/3001):"
echo " - ต้องให้ Node serve ไฟล์ static ด้วย และ path ต้องตรง (เช่น BASE=/realtimechat)"
echo "ถ้า Nginx ใช้ root/alias ไปที่โฟลเดอร์:"
echo " - ต้องชี้ไปที่โฟลเดอร์ที่มี index.html จริง (เช่น $WWW/realtimechat/public ถ้า index อยู่ที่ public)"
echo ""
echo "ตัวอย่าง location ที่ serve ไฟล์จาก disk (ไม่ผ่าน Node):"
echo ' location /realtimechat/ {'
echo " alias $WWW/realtimechat/public/;"
echo " try_files \$uri \$uri/ /realtimechat/index.html;"
echo ' }'
echo ""
echo "หลังจากแก้ config แล้วรัน: sudo nginx -t && sudo systemctl reload nginx"