Nginx try\u文件忽略路径

Nginx try\u文件忽略路径,nginx,Nginx,我有一个图像的位置设置,如: location ~* ^/images/.+\.(jpg|jpeg|gif|png)$ { try_files /disk/$uri /images?uri=$uri; } $uri包含图像名称。当我访问/images/one/two/three/item.jpg时,我想从try\u文件中排除图像。因此,访问它实际上应该是尝试/disk/one/two/three/item.jpg 知道如何排除第一段吗?首先,我将用前缀位置包装正则表达式位置。这将隔离re

我有一个图像的位置设置,如:

location ~* ^/images/.+\.(jpg|jpeg|gif|png)$ {
   try_files /disk/$uri /images?uri=$uri;
}
$uri
包含
图像
名称。当我访问
/images/one/two/three/item.jpg
时,我想从try\u文件中排除
图像。因此,访问它实际上应该是尝试
/disk/one/two/three/item.jpg


知道如何排除第一段吗?

首先,我将用前缀位置包装正则表达式位置。这将隔离regex位置并防止它与其他位置冲突。因此,您的配置将更平滑地扩展

如果这个目录中只有图像,那么在/images/之后捕获所有内容就更简单了,而且不必担心文件扩展名。然后,您可以自由进行区分大小写的匹配,这会更快一些

location /images/ {
    location ~ ^/images/(?<img_path>.+) {
        try_files /disk/$img_path /images?uri=$img_path;
    }
}
位置/图像/{
位置^/images/(?。+){
try_files/disk/$img_path/images?uri=$img_path;
}
}