nginx.conf 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # 智裁云前端 Nginx 部署配置(独立子域名方案)
  2. # 三个 Vue 应用分别部署在独立子域名,各自 server 块含 SPA history 回退
  3. # 部署后需 reload: sudo nginx -t && sudo nginx -s reload
  4. # 注意:SSL 证书路径需根据生产服务器实际路径调整
  5. # ==================== 系统管理后台 ====================
  6. server {
  7. listen 443 ssl http2;
  8. server_name platform.smartcut.51zj.cc;
  9. ssl_certificate /etc/nginx/ssl/51zj.cc.crt;
  10. ssl_certificate_key /etc/nginx/ssl/51zj.cc.key;
  11. root /var/www/smartcut/dist/platform-app;
  12. index index.html;
  13. # SPA history 回退:未匹配的路径一律返回 index.html,交由前端路由处理
  14. location / {
  15. try_files $uri $uri/ /index.html;
  16. }
  17. # 静态资源长缓存
  18. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
  19. expires 1y;
  20. add_header Cache-Control "public, immutable";
  21. }
  22. # 后端 API 反代
  23. location /api/ {
  24. proxy_pass http://127.0.0.1:8080;
  25. proxy_set_header Host $host;
  26. proxy_set_header X-Real-IP $remote_addr;
  27. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  28. proxy_set_header X-Forwarded-Proto $scheme;
  29. }
  30. # 健康检查 / 监控
  31. location /health { proxy_pass http://127.0.0.1:8080; }
  32. location /metrics { proxy_pass http://127.0.0.1:8080; }
  33. gzip on;
  34. gzip_vary on;
  35. gzip_min_length 1024;
  36. gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  37. }
  38. # ==================== 工厂管理后台 ====================
  39. server {
  40. listen 443 ssl http2;
  41. server_name factory.smartcut.51zj.cc;
  42. ssl_certificate /etc/nginx/ssl/51zj.cc.crt;
  43. ssl_certificate_key /etc/nginx/ssl/51zj.cc.key;
  44. root /var/www/smartcut/dist/factory-app;
  45. index index.html;
  46. location / {
  47. try_files $uri $uri/ /index.html;
  48. }
  49. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
  50. expires 1y;
  51. add_header Cache-Control "public, immutable";
  52. }
  53. location /api/ {
  54. proxy_pass http://127.0.0.1:8080;
  55. proxy_set_header Host $host;
  56. proxy_set_header X-Real-IP $remote_addr;
  57. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  58. proxy_set_header X-Forwarded-Proto $scheme;
  59. }
  60. location /health { proxy_pass http://127.0.0.1:8080; }
  61. location /metrics { proxy_pass http://127.0.0.1:8080; }
  62. gzip on;
  63. gzip_vary on;
  64. gzip_min_length 1024;
  65. gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  66. }
  67. # ==================== 工人端 ====================
  68. server {
  69. listen 443 ssl http2;
  70. server_name worker.smartcut.51zj.cc;
  71. ssl_certificate /etc/nginx/ssl/51zj.cc.crt;
  72. ssl_certificate_key /etc/nginx/ssl/51zj.cc.key;
  73. root /var/www/smartcut/dist/worker-app;
  74. index index.html;
  75. location / {
  76. try_files $uri $uri/ /index.html;
  77. }
  78. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
  79. expires 1y;
  80. add_header Cache-Control "public, immutable";
  81. }
  82. location /api/ {
  83. proxy_pass http://127.0.0.1:8080;
  84. proxy_set_header Host $host;
  85. proxy_set_header X-Real-IP $remote_addr;
  86. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  87. proxy_set_header X-Forwarded-Proto $scheme;
  88. }
  89. location /health { proxy_pass http://127.0.0.1:8080; }
  90. location /metrics { proxy_pass http://127.0.0.1:8080; }
  91. gzip on;
  92. gzip_vary on;
  93. gzip_min_length 1024;
  94. gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  95. }
  96. # ==================== HTTP → HTTPS 重定向 ====================
  97. server {
  98. listen 80;
  99. server_name platform.smartcut.51zj.cc factory.smartcut.51zj.cc worker.smartcut.51zj.cc;
  100. return 301 https://$host$request_uri;
  101. }