48 lines
1.9 KiB
Plaintext
48 lines
1.9 KiB
Plaintext
# ตัวอย่าง Nginx สำหรับ realtimechat และ Game (แก้ 404)
|
|
# นำส่วนที่เกี่ยวข้องไปใส่ใน server { } ของ srv1361159.hstgr.cloud
|
|
|
|
# ---- วิธีที่ A: ใช้ alias ให้ Nginx serve ไฟล์ static เอง ----
|
|
# ถ้า index.html อยู่ที่ /var/www/html/realtimechat/public/index.html
|
|
location /realtimechat/ {
|
|
alias /var/www/html/realtimechat/public/;
|
|
try_files $uri $uri/ /realtimechat/index.html;
|
|
# ส่ง /realtimechat/socket.io ไปที่ Node
|
|
location ~ ^/realtimechat/socket\.io/ {
|
|
proxy_pass http://127.0.0.1:3000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}
|
|
}
|
|
|
|
location /Game/ {
|
|
alias /var/www/html/Game/public/;
|
|
try_files $uri $uri/ /Game/index.html;
|
|
location ~ ^/Game/socket\.io/ {
|
|
proxy_pass http://127.0.0.1:3001;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}
|
|
}
|
|
|
|
# ---- วิธีที่ B: proxy ทั้งหมดไปที่ Node (ถ้า Node serve ไฟล์ด้วย path ถูก) ----
|
|
# location /realtimechat/ {
|
|
# proxy_pass http://127.0.0.1:3000/;
|
|
# proxy_http_version 1.1;
|
|
# proxy_set_header Upgrade $http_upgrade;
|
|
# proxy_set_header Connection "upgrade";
|
|
# proxy_set_header Host $host;
|
|
# proxy_set_header X-Real-IP $remote_addr;
|
|
# }
|
|
# location /Game/ {
|
|
# proxy_pass http://127.0.0.1:3001/;
|
|
# ... เหมือนด้านบน
|
|
# }
|
|
|
|
# หลังแก้: sudo nginx -t && sudo systemctl reload nginx
|