From b525085e2b470503774082a2eed19c046de91c5b Mon Sep 17 00:00:00 2001 From: giteaadmin Date: Fri, 24 Apr 2026 08:25:30 +0000 Subject: [PATCH] =?UTF-8?q?Initial:=20Project=20justice=20=E2=80=94=20ngin?= =?UTF-8?q?x=20srv1361159.hstgr.cloud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- .gitignore | 1 + README.md | 23 ++++++++ nginx/srv1361159.hstgr.cloud | 102 +++++++++++++++++++++++++++++++++++ scripts/deploy-nginx.sh | 8 +++ scripts/save-from-etc.sh | 15 ++++++ 5 files changed, 149 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 nginx/srv1361159.hstgr.cloud create mode 100755 scripts/deploy-nginx.sh create mode 100755 scripts/save-from-etc.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea82dee --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Project justice + +Git สำหรับเก็บ **เฉพาะ** ไฟล์ Nginx ของ `https://srv1361159.hstgr.cloud` (ไม่รวม vhost อื่น เช่น git.*) + +## Layout + +- `nginx/srv1361159.hstgr.cloud` — mirror ของ `/etc/nginx/sites-available/srv1361159.hstgr.cloud` + +## หลังแก้ใน repo แล้ว (นำขึ้น production) + +```bash +sudo /root/repos/justice/scripts/deploy-nginx.sh +``` + +## แก้ที่ `/etc/nginx/...` โดยตรง → ดึงเข้า repo + commit + push + +```bash +/root/repos/justice/scripts/save-from-etc.sh "อธิบายการเปลี่ยนแปลง" +``` + +## Remote + +- https://git.srv1361159.hstgr.cloud/giteaadmin/justice.git diff --git a/nginx/srv1361159.hstgr.cloud b/nginx/srv1361159.hstgr.cloud new file mode 100644 index 0000000..e7a76b2 --- /dev/null +++ b/nginx/srv1361159.hstgr.cloud @@ -0,0 +1,102 @@ +# Nginx สำหรับ srv1361159.hstgr.cloud — ใช้แทนของเดิมใน /etc/nginx/sites-available/ +# คัดลอกไปที่เซิร์ฟเวอร์: sudo cp srv1361159.hstgr.cloud.conf /etc/nginx/sites-available/srv1361159.hstgr.cloud +# แล้ว: sudo nginx -t && sudo systemctl reload nginx + +server { + server_name srv1361159.hstgr.cloud; + root /var/www/html; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ =404; + } + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass unix:/run/php/php8.3-fpm.sock; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + location ~ /\.ht { + deny all; + } + + location ^~ /Admin/private/ { + deny all; + return 404; + } + + # RealtimeChat — ไฟล์จากโฟลเดอร์ + Socket.IO ไป Node + location /realtimechat/ { + alias /var/www/html/realtimechat/public/; + index index.html; + try_files $uri $uri/ /realtimechat/index.html; + } + 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; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # Game (ZEP-like) — รูปตัวละครอยู่ที่ Node (data/characters) + location /Game/img/characters/ { + proxy_pass http://127.0.0.1:3001; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + # Game — API ต้องรับ body ใหญ่ (รูปพื้นหลัง base64) จึงตั้ง 20M + location /Game/api/ { + client_max_body_size 20M; + proxy_pass http://127.0.0.1:3001; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + location ~ ^/Game/(?!socket\.io/)(.+\.(html|js))$ { + alias /var/www/html/Game/public/$1; + add_header Cache-Control "no-store, no-cache, must-revalidate"; + } + location /Game/ { + alias /var/www/html/Game/public/; + index index.html; + 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; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + listen [::]:443 ssl ipv6only=on; + listen 443 ssl; + ssl_certificate /etc/letsencrypt/live/srv1361159.hstgr.cloud/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/srv1361159.hstgr.cloud/privkey.pem; + include /etc/letsencrypt/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; +} + +server { + if ($host = srv1361159.hstgr.cloud) { + return 301 https://$host$request_uri; + } + listen 80 default_server; + listen [::]:80 default_server; + server_name srv1361159.hstgr.cloud; + return 404; +} diff --git a/scripts/deploy-nginx.sh b/scripts/deploy-nginx.sh new file mode 100755 index 0000000..4bad852 --- /dev/null +++ b/scripts/deploy-nginx.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -euo pipefail +SRC="$(cd "$(dirname "$0")/.." && pwd)/nginx/srv1361159.hstgr.cloud" +DST="/etc/nginx/sites-available/srv1361159.hstgr.cloud" +install -o root -g root -m 644 "$SRC" "$DST" +nginx -t +systemctl reload nginx +echo "OK: deployed $SRC -> $DST and nginx reloaded." diff --git a/scripts/save-from-etc.sh b/scripts/save-from-etc.sh new file mode 100755 index 0000000..e1cf4a0 --- /dev/null +++ b/scripts/save-from-etc.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -euo pipefail +REPO="$(cd "$(dirname "$0")/.." && pwd)" +MSG="${1:-Update nginx srv1361159.hstgr.cloud}" +cp -a /etc/nginx/sites-available/srv1361159.hstgr.cloud "$REPO/nginx/srv1361159.hstgr.cloud" +cd "$REPO" +git add nginx/srv1361159.hstgr.cloud README.md scripts 2>/dev/null || git add nginx/srv1361159.hstgr.cloud +if git diff --cached --quiet 2>/dev/null; then + echo "No changes to commit." + exit 0 +fi +git commit -m "$MSG" || true +TOKEN="$(cat /root/.config/gitea-justice.token)" +git push "https://giteaadmin:${TOKEN}@git.srv1361159.hstgr.cloud/giteaadmin/justice.git" main +echo "OK: committed and pushed."