gpt4 book ai didi

http - 如何阻止 nginx 将图像 URL 视为实际文件?

转载 作者:可可西里 更新时间:2023-11-01 16:21:50 27 4
gpt4 key购买 nike

抱歉这个糟糕的标题;很难解释

我的网站内置了一个搜索功能,使用方式如下:

http://www.example.com/search/queryhere

问题是当我尝试搜索文件名时,例如:

http://www.example.com/search/hello.jpg

我得到一个 nginx 404 页面,据说是因为 search/hello.jpg 正试图打开。一种解决方法是在请求路径中添加一个正斜杠,但我想要一个更永久的解决方案。我该如何解决这个问题?

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
access_log off;
}

最佳答案

告诉 nginx 仅对现有 文件执行额外指令:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
if (-f $request_filename) {
expires max;
log_not_found off;
access_log off;
}
}

也许有更好的方法不需要 if...

According to nginx pitfalls :

Using if to ensure a file exists is horrible. It's mean. If you have any recent version of Nginx you should look at try_files which just made life much easier.

关于http - 如何阻止 nginx 将图像 URL 视为实际文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20530038/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com