Nginx位置的多个根

Nginx位置的多个根,nginx,location,root,Nginx,Location,Root,我有一个这样定义的位置 location ~ \.(jpg|jpeg|png|gif|swf|flv|mp4|mov|avi|wmv|m4v|mkv|ico|css|js|txt|html|htm)$ { root /path/to/static/files/; } 如果我请求/events.js,它位于/path/to/static/files/中,则可以正常工作 但是如果我请求/func.js中的/other/path/to/static/files/文件,它将找不到它 所以我需要

我有一个这样定义的位置

location ~ \.(jpg|jpeg|png|gif|swf|flv|mp4|mov|avi|wmv|m4v|mkv|ico|css|js|txt|html|htm)$ {
    root /path/to/static/files/;
}
如果我请求
/events.js
,它位于
/path/to/static/files/
中,则可以正常工作

但是如果我请求
/func.js
中的
/other/path/to/static/files/
文件,它将找不到它

所以我需要的是两个可以找到静态文件的位置。这两个请求之间没有任何其他区别,它们来自同一个应用程序。唯一的区别是文件的物理位置。我也不知道这些文件的名字,它们完全是随机的

解决方案
请尝试以下操作:

location ~ \.(jpg|jpeg|png|gif|swf|flv|mp4|mov|avi|wmv|m4v|mkv|ico|css|js|txt|html|htm)$ {
  root /;
  try_files /path/to/static/files/$uri /other/path/to/static/files/$uri;
}
看看它是如何工作的

location ~ \.(jpg|jpeg|png|gif|swf|flv|mp4|mov|avi|wmv|m4v|mkv|ico|css|js|txt|html|htm)$ {
  root /;
  try_files /path/to/static/files/$uri /other/path/to/static/files/$uri;
}