【问题标题】:Nginx try_files not working regexpNginx try_files 不工作正则表达式
【发布时间】:2018-04-01 20:54:40
【问题描述】:

我在我的 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 看不到磁盘上的文件?

【问题讨论】:

  • 你能不能也给我们看看 nginx 日志?
  • @IvanVelichko,看看我的回答:)

标签: nginx location


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 2013-03-12
    • 2012-04-24
    • 2020-08-15
    • 2014-08-19
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多