nginx URL重写子文件夹

我有2个子文件夹,它们在my_url / test1和my_url / test2上打开

location /test1 { index index.html index.php; ## Allow a static html file to be shown first try_files $uri $uri/ /test1 /index.php; expires 30d; ## Assume all files are cachable } location /test2 { index index.html index.php; ## Allow a static html file to be shown first try_files $uri $uri/ /test2/index.php; expires 30d; ## Assume all files are cachable } 

我想添加3个额外的testing子文件夹(test3,test4,test5)我可以继续写:

 location /test3 { index index.html index.php; ## Allow a static html file to be shown first try_files $uri $uri/ /test3/index.php; expires 30d; ## Assume all files are cachable } 

等等。但是可能有一些非常规的configuration方式吗? 喜欢

 location /(subfolder) { index index.html index.php; ## Allow a static html file to be shown first try_files $uri $uri/ /(subfolder)/index.php; expires 30d; ## Assume all files are cachable } 

你几乎把它放在你的最后一个位置声明上,只需将/(subfolder)replace为/ ,将行上的子文件夹stringreplace为/(subfolder)/index.php而将try_filesreplace为/(subfolder)/index.php

 location / { index index.html index.php; try_files $uri $uri/ /$uri/index.php; expires 30d; }