【发布时间】:2015-08-19 07:47:37
【问题描述】:
我使用 nginx 1.6.2 从文件夹中提供静态图像。如果存在或回退到默认图像,我需要提供请求的文件。
我有这个位置块
location /test/img/ {
rewrite ^/test/img/(.*) /$1 break;
root /path/to/folder/images;
try_files $uri /default.jpg;
}
“/path/to/folder/images”文件夹包含 2 个文件:image1.jpg 和 default.jpg。 如果我请求现有图像,则一切正常。例如,如果我在这个 url 上做一个 GET
<host_name>/test/img/image1.jpg
我可以看到正确的图像,但如果我搜索未知图像,我会收到 404 响应。 从 error.log 文件中我可以看到这个错误:
[error] 18128#0: *1 open() "/etc/nginx/html/default.jpg" failed (2: No such file or directory)
为什么 nginx 在那个文件夹中搜索 default.jpg?我希望在 location 块的根目录中搜索该文件。我尝试使用绝对路径但没有成功。 提前致谢。
【问题讨论】:
标签: nginx static-files fallback