Files
danyang-match/h5-demo/nginx-h5.conf
T

50 lines
2.0 KiB
Plaintext
Raw Normal View History

2026-10-19 20:36:22 +08:00
# H5 演示端 Nginx 配置(单页应用)
#
# 与 admin-web/nginx-admin.conf 同构:产物挂在 /h5/ 子路径下(vite build base=/h5/)。
# 上游入口(生产 nginx、本地整套栈 nginx)都**不剥离** /h5 前缀地转发到本容器,
# 因此这里必须自己认识这个前缀。
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# 根路径没有内容:H5 产物挂在 /h5/ 子路径下。显式 301 避免"打根路径拿到空白/错页"的假成功。
location = / {
return 301 /h5/;
}
# SPA:/h5/** 映射到产物根目录。
# try_files 兜底写成 URI(/h5/index.html)而不是文件路径:alias + try_files 的已知坑。
location /h5/ {
alias /usr/share/nginx/html/;
try_files $uri $uri/ /h5/index.html;
}
# API proxy —— 演示端与管理端共用同一后端,数据天然一致(联动的关键)。
# 用 resolver + 变量 proxy_pass:避免 nginx 启动时 backend DNS 未就绪就 [emerg] 退出。
resolver 127.0.0.11 valid=30s ipv6=off;
set $backend_upstream "http://backend:8080";
location /api/ {
proxy_pass $backend_upstream;
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;
}
# 用户间即时聊天已下线:与顶层 nginx 一致返回 410,避免演示端误以为可聊。
location /ws/ {
default_type application/json;
return 410 '{"success":false,"code":"CHAT_DISABLED","message":"平台未提供用户之间的即时聊天功能","data":null}';
}
}