Nginx try_files无效regexp

时间:2017-10-20 16:19:51

标签: nginx location

我在我的nginx配置文件中创建了一个位置:

location ~* ^/resize/(.*)/(\d+)/(\d+)/(.*)\.(jpeg|jpg|png|gif)$ {
    try_files /var/image-gallery/php/web/assert/$1/$4_$2_$3.$5 /resize.php?storage=$1&width=$2&height=$3&file=$4&ext=$5;
}

如果文件存在,我希望nginx返回它。否则我想运行一个应该最终流式传输文件内容的脚本。

HTTP请求示例:http://host:8000/resize/storage3/100/100/28f686ecb64bbb0c90d824a4be08a1e9.jpeg

档案位置:

$ file /var/image-gallery/php/web/assert/storage3/28f686ecb64bbb0c90d824a4be08a1e9_100_100.jpeg
/var/image-gallery/php/web/assert/storage3/28f686ecb64bbb0c90d824a4be08a1e9_100_100.jpeg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 100x100, frames 3

为什么nginx无法在磁盘上看到该文件?

1 个答案:

答案 0 :(得分:1)

解决! Nginx不使用绝对路径。

修正:

location ~* ^/resize/(.*)/(\d+)/(\d+)/(.*)\.(jpeg|jpg|png|gif)$ {
   root /var/image-gallery/php/web/assert;
   try_files /$1/$4_$2_$3.$5 /resize.php?storage=$1&width=$2&height=$3&file=$4&ext=$5;
}