# HSOSKY PlayWeb - cau hinh nginx mau # # Dat vao /etc/nginx/sites-available/playweb roi: # ln -s /etc/nginx/sites-available/playweb /etc/nginx/sites-enabled/ # nginx -t && systemctl reload nginx # # Doi server_name va duong dan root cho khop may cua ban. server { listen 80; listen [::]:80; server_name play.hsosky.com; # <-- doi ten mien root /var/www/playweb/public; # <-- doi duong dan index index.html; # ---- Nen ---- # gzip_static uu tien file .gz da nen san (classes.js.gz 765KB thay vi # 10.4MB). Neu ban nginx khong co module nay thi bo dong duoi va dua vao # gzip on ben duoi. gzip_static on; gzip on; gzip_vary on; gzip_comp_level 6; gzip_min_length 1024; gzip_types application/javascript text/javascript text/css text/html application/json image/svg+xml; # ---- Cau noi WebSocket -> TCP (BAT BUOC) ---- # Khong co phan nay thi game khong the ket noi may chu, se ket o man # dang nhap. bridge.mjs phai dang chay o 127.0.0.1:8081. location /socket-bridge { proxy_pass http://127.0.0.1:8081; 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; # Ket noi game mo lau va co luc im lang -> dung de nginx tu ngat proxy_read_timeout 1h; proxy_send_timeout 1h; proxy_buffering off; } # ---- Tai nguyen co danh phien ban (?v=N) ---- # App luon goi kem ?v=N va doi so do moi khi noi dung doi, nen cache # duoc vinh vien. Neu ban mo thang /classes.js khong kem ?v thi co the # nhan ban cu trong cache - do la danh doi da biet truoc. location ~* \.(js|css)$ { add_header Cache-Control "public, max-age=31536000, immutable"; access_log off; } # ---- JAR tai nguyen game ---- # Khong danh phien ban nen dung ETag: het han thi hoi lai, giong nhau # thi nhan 304 rong thay vi tai lai 2.7MB. location ~* \.(jar|jad)$ { add_header Cache-Control "public, max-age=3600, must-revalidate"; access_log off; } # ---- Trang HTML ---- # Khong duoc cache lau: day la cho chua so ?v moi, cache no la nguoi # choi mac ket o ban cu. location = /index.html { add_header Cache-Control "no-cache"; } location = /play.html { add_header Cache-Control "no-cache"; } # /play chay duoc nhu /play.html location = /play { try_files /play.html =404; } location / { try_files $uri $uri/ /index.html; } } # ---- HTTPS ---- # Sau khi chay certbot, no tu them block 443. Luu y: trang https thi game # tu dung wss:// - khoi phai sua gi, mien la location /socket-bridge o tren # duoc chep sang block 443 (certbot thuong tu lam).