从$uringinx获取部分

从$uringinx获取部分,nginx,nginx-location,Nginx,Nginx Location,我现在正在学习NGINX上的location指令,然后我需要只获取$uri的一部分 例如,URL是http://example.com/2019/10/92/cat/file.mp4,然后在NGINX上使用$uri将获得:/2019/10/92/cat/file.mp4。有没有办法只获取$uri的一部分 我的目标是从URLhttp://example.com/2019/10/92/cat/file.mp4 这必须适用于任何URL,并且仍然产生相同深度的目录: http://example.com

我现在正在学习NGINX上的location指令,然后我需要只获取$uri的一部分

例如,URL是
http://example.com/2019/10/92/cat/file.mp4
,然后在NGINX上使用$uri将获得:
/2019/10/92/cat/file.mp4
。有没有办法只获取$uri的一部分

我的目标是从URL
http://example.com/2019/10/92/cat/file.mp4

这必须适用于任何URL,并且仍然产生相同深度的目录:

http://example.com/2019/10/92/cat/file.mp4
->
/2019/10/92/cat
http://example.com/2019/10/92/cat/cat_2/file.mp4
->
/2019/10/92/cat


非常感谢您的帮助。

您应该使用regex

location ~* ^/(?<somepartfromuri>.*)/*.mp4 {
      set $myvar ${somepartfromuri};
位置~*^/(?*)/*.mp4{
设置$myvar${somepartfromuri};
(未测试)