110 lines
5.0 KiB
Plaintext
110 lines
5.0 KiB
Plaintext
# ═══════════════════════════════════════════════════════════════════
|
||
# 清渊传奇 H5 游戏平台 — Nginx 反向代理配置
|
||
# 路径:/etc/nginx/conf.d/chuanqi.conf
|
||
# ═══════════════════════════════════════════════════════════════════
|
||
#
|
||
# 架构说明:
|
||
# ┌─────────────────────────────────────────┐
|
||
# │ 浏览器 │
|
||
# │ ↓ HTTPS :443 / HTTP :80 │
|
||
# │ Nginx │
|
||
# │ ├── /api/* → Node.js :3001 │
|
||
# │ ├── /public/* → 静态文件(Egret) │
|
||
# │ └── 其他 → Vue dist 目录 │
|
||
# └─────────────────────────────────────────┘
|
||
#
|
||
# ═══════════════════════════════════════════════════════════════════
|
||
|
||
upstream chuanqi_api {
|
||
server 127.0.0.1:3001;
|
||
keepalive 32;
|
||
}
|
||
|
||
# ─── HTTP → HTTPS 重定向 ──────────────────────────────────────────
|
||
server {
|
||
listen 80;
|
||
server_name your-domain.com;
|
||
|
||
# Let's Encrypt / ACME 验证(如使用)
|
||
location /.well-known/acme-challenge/ {
|
||
root /var/www/html;
|
||
}
|
||
|
||
location / {
|
||
return 301 https://$host$request_uri;
|
||
}
|
||
}
|
||
|
||
# ─── HTTPS 主配置 ─────────────────────────────────────────────────
|
||
server {
|
||
listen 443 ssl http2;
|
||
server_name your-domain.com;
|
||
|
||
# ── SSL 证书(替换为实际路径)─────────────────────────────────
|
||
ssl_certificate /etc/ssl/certs/your-domain.crt;
|
||
ssl_certificate_key /etc/ssl/private/your-domain.key;
|
||
ssl_protocols TLSv1.2 TLSv1.3;
|
||
ssl_ciphers HIGH:!aNULL:!MD5;
|
||
ssl_session_cache shared:SSL:10m;
|
||
ssl_session_timeout 10m;
|
||
|
||
# ── 基础配置 ──────────────────────────────────────────────────
|
||
charset utf-8;
|
||
client_max_body_size 20m;
|
||
|
||
# ── 0. 屏蔽 PHP 文件直接访问(PHP 已停用,防止残留文件被暴露)──
|
||
location ~* \.php$ {
|
||
return 404;
|
||
}
|
||
|
||
# ── 1. API 请求 → Node.js ─────────────────────────────────────
|
||
location /api/ {
|
||
proxy_pass http://chuanqi_api;
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Connection "";
|
||
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;
|
||
proxy_read_timeout 30s;
|
||
proxy_connect_timeout 10s;
|
||
}
|
||
|
||
# ── 2. Egret 游戏静态资源(大量小文件,强缓存)──────────────
|
||
location /public/ {
|
||
alias /path/to/chuanqi-qycq-web/public/;
|
||
expires 30d;
|
||
add_header Cache-Control "public, immutable";
|
||
access_log off;
|
||
}
|
||
|
||
# ── 3. 游戏入口 js(每次重载)─────────────────────────────────
|
||
location ~* ^/js/(index|loader|microclient)\.js$ {
|
||
root /path/to/chuanqi-qycq-web;
|
||
expires -1;
|
||
add_header Cache-Control "no-cache, no-store";
|
||
}
|
||
|
||
# ── 4. 其他静态资源(图片/字体等,适度缓存)─────────────────
|
||
location ~* \.(png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot)$ {
|
||
root /path/to/chuanqi-qycq-web/module/web/dist;
|
||
expires 7d;
|
||
add_header Cache-Control "public";
|
||
access_log off;
|
||
}
|
||
|
||
# ── 5. Vue 前端(dist,HTML5 History 模式)───────────────────
|
||
location / {
|
||
root /path/to/chuanqi-qycq-web/module/web/dist;
|
||
index index.html;
|
||
# SPA 路由回退
|
||
try_files $uri $uri/ /index.html;
|
||
expires -1;
|
||
add_header Cache-Control "no-cache";
|
||
}
|
||
|
||
# ── 日志 ──────────────────────────────────────────────────────
|
||
access_log /var/log/nginx/chuanqi_access.log;
|
||
error_log /var/log/nginx/chuanqi_error.log warn;
|
||
}
|