123 lines
4.2 KiB
Plaintext
123 lines
4.2 KiB
Plaintext
server {
|
||
listen 80;
|
||
server_name 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;
|
||
|
||
# 启用 HTTP/2(如果使用 HTTPS)
|
||
# listen 443 ssl http2;
|
||
|
||
# 静态文件根目录
|
||
root /usr/share/nginx/html;
|
||
|
||
# ============ API 代理配置(放在最前面,使用 ^~ 提高优先级)============
|
||
|
||
# RBAC 权限管理服务代理
|
||
location ^~ /rbac {
|
||
proxy_pass http://43.139.210.35:5281;
|
||
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;
|
||
proxy_set_header X-Forwarded-Host $host;
|
||
proxy_connect_timeout 30s;
|
||
proxy_send_timeout 30s;
|
||
proxy_read_timeout 30s;
|
||
proxy_buffering off;
|
||
}
|
||
|
||
# trackApi 服务代理(使用 ^~ 确保优先匹配)
|
||
location ^~ /api/trackApi {
|
||
rewrite ^/api/trackApi(.*)$ $1 break;
|
||
proxy_pass http://43.139.210.35:8889;
|
||
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;
|
||
proxy_connect_timeout 30s;
|
||
proxy_send_timeout 30s;
|
||
proxy_read_timeout 30s;
|
||
}
|
||
|
||
# 排除前端路由路径,只代理真正的 API 请求
|
||
# 前端路由路径(驼峰命名):upstreamInterface, downstreamInterface, upstreamInterfaceConfig,
|
||
# upstreamInterfaceConfigEdit, appList, requestLog, callStatistics, apiDebugger 等
|
||
# 使用负向前瞻正则,排除这些前端路由路径
|
||
# 前端路由会继续往下走到 location /,由 try_files 返回 index.html(与 /track/ 路由一样)
|
||
location ~ ^/api/(?!(trackApi|upstreamInterface|downstreamInterface|upstreamInterfaceConfig|upstreamInterfaceConfigEdit|appList|requestLog|callStatistics|apiDebugger)) {
|
||
rewrite ^/api(.*)$ $1 break;
|
||
proxy_pass http://43.139.210.35:8888;
|
||
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;
|
||
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 前端路由(放在最后)============
|
||
|
||
location / {
|
||
index index.html;
|
||
try_files $uri $uri/ /index.html;
|
||
|
||
# HTML 不缓存
|
||
location ~* \.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;
|
||
}
|
||
} |