|
|
@@ -1,44 +1,69 @@
|
|
|
-# 智裁云前端Nginx部署配置示例
|
|
|
-# 方案:同一域名子路径部署
|
|
|
+# 智裁云前端 Nginx 部署配置(独立子域名方案)
|
|
|
+# 三个 Vue 应用分别部署在独立子域名,各自 server 块含 SPA history 回退
|
|
|
+# 部署后需 reload: sudo nginx -t && sudo nginx -s reload
|
|
|
+# 注意:SSL 证书路径需根据生产服务器实际路径调整
|
|
|
|
|
|
+# ==================== 系统管理后台 ====================
|
|
|
server {
|
|
|
- listen 80;
|
|
|
- server_name smartcut.example.com;
|
|
|
+ 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;
|
|
|
|
|
|
- # 系统管理后台
|
|
|
- location /platform {
|
|
|
- alias /var/www/smartcut/dist/platform-app;
|
|
|
- try_files $uri $uri/ /platform/index.html;
|
|
|
+ root /var/www/smartcut/dist/platform-app;
|
|
|
+ index index.html;
|
|
|
|
|
|
- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
|
|
|
- expires 1y;
|
|
|
- add_header Cache-Control "public, immutable";
|
|
|
- }
|
|
|
+ # SPA history 回退:未匹配的路径一律返回 index.html,交由前端路由处理
|
|
|
+ location / {
|
|
|
+ try_files $uri $uri/ /index.html;
|
|
|
}
|
|
|
|
|
|
- # 工厂管理后台
|
|
|
- location /factory {
|
|
|
- alias /var/www/smartcut/dist/factory-app;
|
|
|
- try_files $uri $uri/ /factory/index.html;
|
|
|
+ # 静态资源长缓存
|
|
|
+ location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
|
|
|
+ expires 1y;
|
|
|
+ add_header Cache-Control "public, immutable";
|
|
|
+ }
|
|
|
|
|
|
- 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 /worker {
|
|
|
- alias /var/www/smartcut/dist/worker-app;
|
|
|
- try_files $uri $uri/ /worker/index.html;
|
|
|
+ # 健康检查 / 监控
|
|
|
+ location /health { proxy_pass http://127.0.0.1:8080; }
|
|
|
+ location /metrics { proxy_pass http://127.0.0.1:8080; }
|
|
|
|
|
|
- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
|
|
|
- expires 1y;
|
|
|
- add_header Cache-Control "public, immutable";
|
|
|
- }
|
|
|
+ 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";
|
|
|
}
|
|
|
|
|
|
- # 后端API代理
|
|
|
location /api/ {
|
|
|
proxy_pass http://127.0.0.1:8080;
|
|
|
proxy_set_header Host $host;
|
|
|
@@ -47,22 +72,55 @@ server {
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
}
|
|
|
|
|
|
- # 健康检查
|
|
|
- location /health {
|
|
|
- proxy_pass http://127.0.0.1:8080;
|
|
|
+ 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 /metrics {
|
|
|
+ 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;
|
|
|
- # 建议添加IP白名单限制
|
|
|
- # allow 10.0.0.0/8;
|
|
|
- # deny all;
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
- # Gzip压缩
|
|
|
+ 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;
|
|
|
+}
|