2017-10-20 256 views
1

我在nginx的配置文件創建的位置:Nginx的try_files不工作的正則表達式

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的不能看到磁盤上的文件?

+0

你能否也向我們展示了nginx的日誌? –

+0

@IvanVelichko,看到我的回答:) – dimka3210

回答

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; 
}