
由于有个参数是数字,还是动态的,所以我的预期是想达到类似下面这种(随便写的):
location /test/(\d+)/ { alias /www/demo/; index index.html; } 目前情况是,不能通过 ? 拼接参数,所以只能放到 url 里面了。然后网上找了很多例子也自己调试了很多次,都是无法生效。有没有懂的大佬,麻烦指点一下,谢谢!
最终解决方案:
location ~ ^/test/(\d+)/ { rewrite ^/test/(\d+)/$ /test/index.html?id=$1 last; } location = /test/index.html { alias /www/demo/index.html; } 1 edotac 2023-12-29 17:13:37 +08:00 Nginx 这么配置 ``` location /test/ { alias /www/demo/; index index.html; } ``` 在前端项目中设置 id 的路由匹配,比如 vue 中的 vuerouter |
2 vampuke 2023-12-29 17:14:26 +08:00 location ~ ^/test/(\d+)/$ |
3 beyondstars 2023-12-29 17:15:37 +08:00 要通过正则表达式匹配路径,location 后面应以 ~ 或者 ~* 开头,其中 ~* 是 case-insensitive 的(不区分大小写)。 试试 ``` location ~ ^/test/(\d+)$ { # 你的其它内容 } ``` 详见 - 官方 doc: https://nginx.org/en/docs/http/ngx_http_core_module.html#location - nginx 匹配测试: https://nginx.viraptor.info/ |
4 qize0921 OP |
6 sparkssssssss 2023-12-29 23:18:43 +08:00 /www/demo 去掉/试试 |