Files
zsp-project/docs/deploy/nginx.conf
2026-06-03 20:59:39 +08:00

78 lines
2.3 KiB
Nginx Configuration File
Executable File

# 中尚鹏管理系统 - Nginx 生产配置
# 放置于 /etc/nginx/conf.d/zsp.conf 或 /etc/nginx/sites-enabled/zsp
#
# 前置条件:
# 1. 前端构建产物位于 /var/www/zsp/dist
# 2. 后端服务运行于 127.0.0.1:8080
# 3. 后端静态文件目录 /var/www/zsp/data 可读
server {
listen 80;
server_name your-domain.com;
# 前端静态资源
root /var/www/zsp/dist;
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;
# 前端 SPA 路由:所有非文件/非 API 请求返回 index.html
location / {
try_files $uri $uri/ /index.html;
}
# API 反向代理到后端
location /api/ {
proxy_pass http://127.0.0.1:8080;
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;
# 大文件上传支持(合同附件等)
client_max_body_size 100m;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
}
# 健康检查端点
location /health {
proxy_pass http://127.0.0.1:8080/health;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
access_log off;
}
# 静态文件缓存(合同附件、公司文件等)
location /api/contract-files/ {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
expires 7d;
add_header Cache-Control "public, immutable";
}
location /api/zsp-contract-files/ {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
expires 7d;
add_header Cache-Control "public, immutable";
}
location /api/company-files/ {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
expires 7d;
add_header Cache-Control "public, immutable";
}
# 错误页面
error_page 404 /index.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}