3.9 KiB
3.9 KiB
วิธีอัปโหลด RealtimeChat และ Game ขึ้นเซิร์ฟเวอร์
ตอนนี้ใน workspace มีแอปเต็มแล้วอยู่ที่:
/root/realtimechat/— วิดีโอคอล + แชท (Socket.IO, WebRTC)/root/Game/— เกมแบบ ZEP (ล็อบบี้, สร้างฉาก, เล่น, โซนห้ามซ้อน, ชื่อฉากไม่ซ้ำ)
1. อัปโหลดไฟล์ขึ้นเซิร์ฟเวอร์
ใช้ FTP (user: ftpweb) หรือ File Manager ในพาเนลโฮสต์:
- คัดลอกโฟลเดอร์
realtimechatทั้งโฟลเดอร์ ไปที่/var/www/html/realtimechat
(แทนที่ของเดิมทั้งหมด หรือ merge กับของเดิมแล้วแต่คุณ) - คัดลอกโฟลเดอร์
Gameทั้งโฟลเดอร์ ไปที่/var/www/html/Game
(แทนที่ของเดิมทั้งหมด)
ให้โครงสร้างบนเซิร์ฟเวอร์เป็นแบบนี้:
/var/www/html/
realtimechat/
server.js
package.json
public/
index.html
room.html
css/style.css
js/room.js
Game/
server.js
package.json
public/
index.html
lobby.html
editor.html
play.html
css/style.css
js/lobby.js
js/editor.js
js/play.js
2. ติดตั้ง dependency และรัน Node (บนเซิร์ฟเวอร์ผ่าน SSH)
cd /var/www/html/realtimechat
npm install
cd /var/www/html/Game
npm install
จากนั้นให้ service รัน (ถ้ามี systemd อยู่แล้ว แค่ restart):
sudo systemctl restart realtimechat
sudo systemctl restart game-zep
ถ้ายังไม่มี service สร้างไฟล์:
/etc/systemd/system/realtimechat.service
[Unit]
Description=RealtimeChat Node
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/www/html/realtimechat
ExecStart=/usr/bin/node server.js
Restart=on-failure
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
/etc/systemd/system/game-zep.service
[Unit]
Description=Game ZEP Node
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/www/html/Game
ExecStart=/usr/bin/node server.js
Restart=on-failure
Environment=PORT=3001
[Install]
WantedBy=multi-user.target
จากนั้น:
sudo systemctl daemon-reload
sudo systemctl enable realtimechat game-zep
sudo systemctl start realtimechat game-zep
3. ตั้ง Nginx (ทำไว้แล้วใน DO-ON-SERVER-ONCE.sh)
ต้องมี:
- location /realtimechat/ → alias ไปที่
.../realtimechat/public/ - location /realtimechat/socket.io/ → proxy_pass ไปที่
http://127.0.0.1:3000 - location /Game/ → alias ไปที่
.../Game/public/ - location /Game/socket.io/ → proxy_pass ไปที่
http://127.0.0.1:3001
4. ลิงก์ที่ใช้
- RealtimeChat: https://srv1361159.hstgr.cloud/realtimechat/
- Game หน้าหลัก: https://srv1361159.hstgr.cloud/Game/
- สร้าง/แก้ฉาก: https://srv1361159.hstgr.cloud/Game/editor.html
- ล็อบบี้: https://srv1361159.hstgr.cloud/Game/lobby.html
หลังอัปโหลดและ restart service แล้ว หน้าที่หายไปจะกลับมาเป็นแอปเต็ม (วิดีโอคอล + เกมเดินเห็นกัน + แชท) ตามที่ทำกันเมื่อวาน