front/nginx-default.conf
2026-02-06 12:01:39 +08:00

106 lines
3.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============ 生产环境部署必读(避免「本地可以、线上不行」)============
# 1. 本文件必须真正生效:确认 oms.nanafa.com 的请求由「本 server 块」处理
# - 若用 include:确保 include 的是含本 server 的 conf,且无其它 server 抢先匹配
# - 更新后必须执行:nginx -t && nginx -s reload
# 2. /api、/Track 由 nginx 代理到 api.nanafa.com,避免浏览器跨域 405;rbac 由前端直连 admin
# 3. 使用 HTTP(listen 80);root 指向「包含 index.html 的目录」
# ============================================================================
server {
listen 80; # HTTP
server_name oms.nanafa.com 10.1.20.6;
# 启用gzip压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json application/xml image/svg+xml;
gzip_comp_level 6;
gzip_disable "msie6";
# 启用 Brotli 压缩(需要安装 nginx-module-brotli,压缩率比 gzip 高 15-20%)
# 如果服务器支持,取消下面的注释
# brotli on;
# brotli_comp_level 6;
# brotli_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json application/xml image/svg+xml;
# 静态文件根目录
root /usr/share/nginx/html;
# ============ API 代理(同源请求,避免跨域 405)============
location ^~ /api/ {
rewrite ^/api/(.*)$ /itfx/$1 break;
proxy_pass http://api.nanafa.com;
proxy_http_version 1.1;
proxy_set_header Host api.nanafa.com;
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_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
location ^~ /Track {
rewrite ^/Track(.*)$ /track/Track$1 break;
proxy_pass http://api.nanafa.com;
proxy_http_version 1.1;
proxy_set_header Host api.nanafa.com;
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_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
# ============ 静态资源缓存配置 ============
# 带hash的JS/CSS文件 - 长期缓存
location ~* \.(?:js|css)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# 图片资源 - 长期缓存
location ~* \.(?:jpg|jpeg|png|gif|ico|svg|webp|avif)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# 字体文件 - 长期缓存
location ~* \.(?:woff2?|ttf|eot|otf)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# 其他静态资源
location ~* \.(?:pdf|zip|tar|gz)$ {
expires 1M;
add_header Cache-Control "public";
access_log off;
}
# ============ SPA 前端路由(放在最后)============
# 所有非文件请求都回落到 index.html,避免刷新/直接访问子路径 404
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
# HTML 不缓存(单独 location 避免嵌套导致 fallback 异常)
location = /index.html {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# 错误页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}