vasen-website.conf 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # =============================================================================
  2. # vasen-website nginx 配置(精简版,仅含 vasen-website 相关路由)
  3. #
  4. # 本配置从生产环境的 file-upload.conf 中裁剪,去除了 file-upload/eye-demo/
  5. # buffett/gaokao/notes/ocr 等无关业务,仅保留 vasen-website 的完整路由。
  6. #
  7. # 部署方式:将本文件内容合并到你的 nginx server 块中(需 listen ssl + 证书)。
  8. # 若作为独立 server,补上 listen/server_name/ssl 配置(见下方注释)。
  9. # =============================================================================
  10. # ---- 如需独立 server,取消注释并修改 ----
  11. # server {
  12. # listen 8443 ssl;
  13. # server_name your-domain.com;
  14. # ssl_certificate /path/to/cert.pem;
  15. # ssl_certificate_key /path/to/key.pem;
  16. # ssl_protocols TLSv1.2 TLSv1.3;
  17. # ssl_ciphers HIGH:!aNULL:!MD5;
  18. # ---- vasen-website 主路由 ----
  19. # 项目路径(修改为你的实际部署路径)
  20. # root /lio/projects/vasen-website;
  21. location /vasen-website/ {
  22. alias /lio/projects/vasen-website/;
  23. index index.html;
  24. # try_files: 优先尝试 $uri.html(线上 PHP 无扩展名路由的本地 fallback),
  25. # 再试目录,避免同名目录(about/ news/)优先匹配导致 403
  26. try_files $uri $uri.html $uri/ $uri/index.html =404;
  27. # ---- water-cology SPA(Vue hash 路由)----
  28. # 用 ^~ 前缀修饰符,优先级高于正则 location,确保 JS/CSS 也走这里并带 CORS 头
  29. location ^~ /vasen-website/water-cology/ {
  30. alias /lio/projects/vasen-website/water-cology/;
  31. index index.html;
  32. try_files $uri $uri/ /vasen-website/water-cology/index.html;
  33. # SPA 用 type=module + crossorigin,所有资源都需要 CORS 头
  34. add_header Access-Control-Allow-Origin "*" always;
  35. # JS/CSS 不缓存(便于改写生效;稳定后可改回 30d)
  36. location ~* \.(js|css)$ {
  37. add_header Cache-Control "no-cache" always;
  38. add_header Access-Control-Allow-Origin "*" always;
  39. }
  40. location ~* \.(png|jpg|jpeg|gif|svg|ico|woff2?|ttf|eot)$ {
  41. expires 30d;
  42. add_header Cache-Control "public";
  43. add_header Access-Control-Allow-Origin "*" always;
  44. }
  45. # HTML 不缓存
  46. location ~* \.html$ {
  47. add_header Access-Control-Allow-Origin "*" always;
  48. add_header Cache-Control "no-cache";
  49. }
  50. # SPA API mock: prod-api/xxx -> prod-api/xxx/index.json
  51. location /vasen-website/water-cology/prod-api/ {
  52. alias /lio/projects/vasen-website/water-cology/prod-api/;
  53. default_type application/json;
  54. add_header Access-Control-Allow-Origin "*" always;
  55. add_header Cache-Control "no-cache";
  56. try_files $uri $uri/index.json =404;
  57. }
  58. }
  59. # ---- Ajax 接口 mock(由 vasen-sync stage04 生成)----
  60. # HTML 片段接口:/ajax/xxx/N -> web/api/xxx/N.html
  61. location ~ ^/vasen-website/ajax/([a-z0-9_]+)/?([0-9a-z]+)?$ {
  62. default_type text/html;
  63. charset utf-8;
  64. add_header Cache-Control "no-cache";
  65. root /lio/projects/vasen-website/web/api;
  66. try_files /$1/$2.html /$1/default.html =204;
  67. access_log off;
  68. }
  69. # /web/index.php/butler/download(高频,626处引用)-> 直接服务本地下载页
  70. location = /vasen-website/web/index.php/butler/download {
  71. root /lio/projects/vasen-website;
  72. try_files /butler/download.html =404;
  73. access_log off;
  74. }
  75. # 表单提交接口:返回成功 JSON
  76. location ~ ^/vasen-website/(product_search|feedback/sendpost|dealer/change_resion)$ {
  77. default_type application/json;
  78. add_header Cache-Control "no-cache";
  79. root /lio/projects/vasen-website/web/api;
  80. try_files /product_search/success.json /default_success.json =204;
  81. access_log off;
  82. }
  83. # 验证码图片
  84. location ~ ^/vasen-website/(feedback/captcha|create_code)$ {
  85. default_type image/png;
  86. root /lio/projects/vasen-website/web/api;
  87. try_files /captcha/captcha.png =204;
  88. access_log off;
  89. }
  90. # HTML 不缓存,便于修改即时生效
  91. location ~* \.html?$ {
  92. add_header Cache-Control "no-cache, must-revalidate";
  93. expires off;
  94. }
  95. # 静态资源长缓存
  96. location ~* \.(js|css|svg|ico|png|jpg|jpeg|gif|woff2?|ttf|eot|pdf)$ {
  97. expires 30d;
  98. add_header Cache-Control "public";
  99. access_log off;
  100. }
  101. }
  102. # 根路径无尾斜杠 -> 跳转带斜杠
  103. location = /vasen-website {
  104. return 301 /vasen-website/;
  105. }
  106. # ---- 如需独立 server,取消注释 ----
  107. # }