# 智裁云前端 Nginx 部署配置(独立子域名方案) # 三个 Vue 应用分别部署在独立子域名,各自 server 块含 SPA history 回退 # 部署后需 reload: sudo nginx -t && sudo nginx -s reload # 注意:SSL 证书路径需根据生产服务器实际路径调整 # ==================== 系统管理后台 ==================== server { listen 443 ssl http2; server_name platform.smartcut.51zj.cc; ssl_certificate /etc/nginx/ssl/51zj.cc.crt; ssl_certificate_key /etc/nginx/ssl/51zj.cc.key; root /var/www/smartcut/dist/platform-app; index index.html; # SPA history 回退:未匹配的路径一律返回 index.html,交由前端路由处理 location / { try_files $uri $uri/ /index.html; } # 静态资源长缓存 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { expires 1y; add_header Cache-Control "public, immutable"; } # 后端 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; } # 健康检查 / 监控 location /health { proxy_pass http://127.0.0.1:8080; } location /metrics { proxy_pass http://127.0.0.1:8080; } gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; } # ==================== 工厂管理后台 ==================== server { listen 443 ssl http2; server_name factory.smartcut.51zj.cc; ssl_certificate /etc/nginx/ssl/51zj.cc.crt; ssl_certificate_key /etc/nginx/ssl/51zj.cc.key; root /var/www/smartcut/dist/factory-app; index index.html; location / { try_files $uri $uri/ /index.html; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { expires 1y; add_header Cache-Control "public, immutable"; } 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; } location /health { proxy_pass http://127.0.0.1:8080; } location /metrics { proxy_pass http://127.0.0.1:8080; } gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; } # ==================== 工人端 ==================== server { listen 443 ssl http2; server_name worker.smartcut.51zj.cc; ssl_certificate /etc/nginx/ssl/51zj.cc.crt; ssl_certificate_key /etc/nginx/ssl/51zj.cc.key; root /var/www/smartcut/dist/worker-app; index index.html; location / { try_files $uri $uri/ /index.html; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { expires 1y; add_header Cache-Control "public, immutable"; } 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; } location /health { proxy_pass http://127.0.0.1:8080; } location /metrics { proxy_pass http://127.0.0.1:8080; } gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; } # ==================== HTTP → HTTPS 重定向 ==================== server { listen 80; server_name platform.smartcut.51zj.cc factory.smartcut.51zj.cc worker.smartcut.51zj.cc; return 301 https://$host$request_uri; }