我更改了答案以使其递归工作:
首先从头开始抛出版本号并将其添加到第一个目录
location ~ "^/([0-9]{1}\.[0-9]{1})/([a-zA-Z0-9]+)/(.*\.doc)$" {
    rewrite     .*  /$2@$1/$3;
}
所以现在网址:
/1.2/junior/many_sub_dir_here/test.doc    ->   /junior@1.2/many_sub_dir_here/test.doc
现在location指令 belove 将用作递归位置(因此您已标记 nginx 以允许递归位置调用):
location ~ "^(/[a-zA-Z0-9]+@)([0-9]{1}\.[0-9]{1})/(([a-zA-Z0-9]+@[0-9]{1}\.[0-9]{1}/)*)([a-zA-Z0-9]+)/(.*\.doc)$" {
    rewrite .* /$1$2/$3$5@$2/$6;        
}
对于您的网址,它将按以下方式工作
/junior@1.2/x1/x2/x3/test.doc           -->   /junior@1.2/x1@1.2/x2/x3/test.doc
  $1 = /junior@
  $2 = 1.2
  $3 = 
  $4 = 
  $5 = x1
  $6 = x2/x3/test.doc
/junior@1.2/x1@1.2/x2/x3/test.doc       -->   /junior@1.2/x1@1.2/x2@1.2/x3/test.doc
  $1 = /junior
  $2 = 1.2
  $3 = x1@1.2/
  $4 = x1@1.2/
  $5 = x2
  $6 = x3/text.doc
/junior@1.2/x1@1.2/x2@1.2/x3/test.doc   -->   /junior@1.2/x1@1.2/x2@1.2/x3@1.2/test.doc
  $1 = /junior@
  $2 = 1.2
  $3 = x1@1.2/x2@1.2/
  $4 = x2@1.2/
  $5 = x3
  $6 = test.doc
最后一个 url 将不再匹配上面location块中的正则表达式,所以这里我们提供了这样的最终位置块:
location ~ ".*(@[0-9]{1}\.[0-9]{1})/[^@/]+\.doc$" {
    root root /usr/home/fs;
    try_files $uri =404;
}