vasen-website.conf 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. # 匹配任意层级路径下的 /ajax/(页面可能在 product/product_info/ 等子目录)
  62. # 参数段支持 数字/数字 形式(如 product_more/68/1),取第一段作为文件名
  63. location ~ ^/vasen-website/.*/ajax/([a-z0-9_]+)/([0-9]+)(?:/[0-9]+)?$ {
  64. default_type text/html;
  65. charset utf-8;
  66. add_header Cache-Control "no-cache";
  67. root /lio/projects/vasen-website/web/api;
  68. try_files /$1/$2.html /$1/default.html =204;
  69. access_log off;
  70. }
  71. location ~ ^/vasen-website/.*/ajax/([a-z0-9_]+)/?$ {
  72. default_type text/html;
  73. charset utf-8;
  74. add_header Cache-Control "no-cache";
  75. root /lio/projects/vasen-website/web/api;
  76. try_files /$1/default.html =204;
  77. access_log off;
  78. }
  79. # 兼容根路径 /ajax/xxx/N
  80. location ~ ^/vasen-website/ajax/([a-z0-9_]+)/([0-9]+)(?:/[0-9]+)?$ {
  81. default_type text/html;
  82. charset utf-8;
  83. add_header Cache-Control "no-cache";
  84. root /lio/projects/vasen-website/web/api;
  85. try_files /$1/$2.html /$1/default.html =204;
  86. access_log off;
  87. }
  88. location ~ ^/vasen-website/ajax/([a-z0-9_]+)/?$ {
  89. default_type text/html;
  90. charset utf-8;
  91. add_header Cache-Control "no-cache";
  92. root /lio/projects/vasen-website/web/api;
  93. try_files /$1/default.html =204;
  94. access_log off;
  95. }
  96. # /web/index.php/butler/download(高频,626处引用)-> 直接服务本地下载页
  97. location = /vasen-website/web/index.php/butler/download {
  98. root /lio/projects/vasen-website;
  99. try_files /butler/download.html =404;
  100. access_log off;
  101. }
  102. # 表单提交接口:返回成功 JSON
  103. location ~ ^/vasen-website/(product_search|feedback/sendpost|dealer/change_resion)$ {
  104. default_type application/json;
  105. add_header Cache-Control "no-cache";
  106. root /lio/projects/vasen-website/web/api;
  107. try_files /product_search/success.json /default_success.json =204;
  108. access_log off;
  109. }
  110. # 验证码图片
  111. location ~ ^/vasen-website/(feedback/captcha|create_code)$ {
  112. default_type image/png;
  113. root /lio/projects/vasen-website/web/api;
  114. try_files /captcha/captcha.png =204;
  115. access_log off;
  116. }
  117. # HTML 不缓存,便于修改即时生效
  118. location ~* \.html?$ {
  119. add_header Cache-Control "no-cache, must-revalidate";
  120. expires off;
  121. }
  122. # 静态资源长缓存
  123. location ~* \.(js|css|svg|ico|png|jpg|jpeg|gif|woff2?|ttf|eot|pdf)$ {
  124. expires 30d;
  125. add_header Cache-Control "public";
  126. access_log off;
  127. }
  128. }
  129. # 根路径无尾斜杠 -> 跳转带斜杠
  130. location = /vasen-website {
  131. return 301 /vasen-website/;
  132. }
  133. # ---- 如需独立 server,取消注释 ----
  134. # }