41 lines
1.3 KiB
Plaintext
41 lines
1.3 KiB
Plaintext
server {
|
||
listen 80;
|
||
server_name _;
|
||
|
||
root /usr/share/nginx/html;
|
||
index index.html;
|
||
|
||
# gzip 压缩
|
||
gzip on;
|
||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript image/svg+xml;
|
||
gzip_min_length 1024;
|
||
|
||
# 后端 API — 匹配已知接口路径前缀
|
||
# 新项目通过 init-project-repos.sh 会将 /test/ 替换为 /项目前缀/
|
||
location ~ ^/test/(sys|oauth2|jmreport|online|generic|drag|actuator|ws|websocket)/ {
|
||
proxy_pass ${BACKEND_PROXY};
|
||
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_read_timeout 120s;
|
||
|
||
# WebSocket 支持
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Upgrade $http_upgrade;
|
||
proxy_set_header Connection "upgrade";
|
||
}
|
||
|
||
# 前端 SPA — 所有非 API 非文件请求回退到 index.html
|
||
location / {
|
||
try_files $uri $uri/ /index.html;
|
||
}
|
||
|
||
# 静态资源长期缓存(Vite 生成的带 hash 文件)
|
||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?|ttf|eot)$ {
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
}
|
||
}
|