front/nginx-default.conf
2025-12-27 16:29:05 +08:00

110 lines
3.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";
# 静态文件根目录
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 请求代理
location ^~ /api {
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;
}
}