Explorar o código

fix: nginx ajax mock 支持嵌套路径和多段参数

产品详情页在 product/product_info/ 二级目录,JS 相对路径 ./ajax/...
解析为嵌套 URL;data-id 含 '/' 导致参数为多段(如 68/1)。
正则改为匹配任意层级路径 + 多段参数(取首段作文件名)。
lio hai 3 meses
pai
achega
956a156ae0
Modificáronse 1 ficheiros con 28 adicións e 1 borrados
  1. 28 1
      nginx/vasen-website.conf

+ 28 - 1
nginx/vasen-website.conf

@@ -63,7 +63,9 @@ location /vasen-website/ {
 
     # ---- Ajax 接口 mock(由 vasen-sync stage04 生成)----
     # HTML 片段接口:/ajax/xxx/N -> web/api/xxx/N.html
-    location ~ ^/vasen-website/ajax/([a-z0-9_]+)/?([0-9a-z]+)?$ {
+    # 匹配任意层级路径下的 /ajax/(页面可能在 product/product_info/ 等子目录)
+    # 参数段支持 数字/数字 形式(如 product_more/68/1),取第一段作为文件名
+    location ~ ^/vasen-website/.*/ajax/([a-z0-9_]+)/([0-9]+)(?:/[0-9]+)?$ {
         default_type text/html;
         charset utf-8;
         add_header Cache-Control "no-cache";
@@ -71,6 +73,31 @@ location /vasen-website/ {
         try_files /$1/$2.html /$1/default.html =204;
         access_log off;
     }
+    location ~ ^/vasen-website/.*/ajax/([a-z0-9_]+)/?$ {
+        default_type text/html;
+        charset utf-8;
+        add_header Cache-Control "no-cache";
+        root /lio/projects/vasen-website/web/api;
+        try_files /$1/default.html =204;
+        access_log off;
+    }
+    # 兼容根路径 /ajax/xxx/N
+    location ~ ^/vasen-website/ajax/([a-z0-9_]+)/([0-9]+)(?:/[0-9]+)?$ {
+        default_type text/html;
+        charset utf-8;
+        add_header Cache-Control "no-cache";
+        root /lio/projects/vasen-website/web/api;
+        try_files /$1/$2.html /$1/default.html =204;
+        access_log off;
+    }
+    location ~ ^/vasen-website/ajax/([a-z0-9_]+)/?$ {
+        default_type text/html;
+        charset utf-8;
+        add_header Cache-Control "no-cache";
+        root /lio/projects/vasen-website/web/api;
+        try_files /$1/default.html =204;
+        access_log off;
+    }
 
     # /web/index.php/butler/download(高频,626处引用)-> 直接服务本地下载页
     location = /vasen-website/web/index.php/butler/download {