location ~* \.(ico|css|js|gif|jpg|png)$ {
> expires 7d;
> }
> If I add this to my server conf it will cause all those requests
> to fail with a 404..I'm feeling silly for missing this, and I
> know it's probably very easy to fix...but how? :)
Most likely you have something like this:
root /path/to/nowhere;
location / {
root /path/to/root;
}
Adding
location ~* \.(ico|css|js|gif|jpg|png)$ {
expires 7d;
}
results in these files being searched in nowhere. The reason is
simple: nginx uses configuration in "location ~* \.(...)$" which
has no root explicitly set, and therefore root is inherited from
server/http level (or compiled-in default).
> expires 7d;
> }
> If I add this to my server conf it will cause all those requests
> to fail with a 404..I'm feeling silly for missing this, and I
> know it's probably very easy to fix...but how? :)
Most likely you have something like this:
root /path/to/nowhere;
location / {
root /path/to/root;
}
Adding
location ~* \.(ico|css|js|gif|jpg|png)$ {
expires 7d;
}
results in these files being searched in nowhere. The reason is
simple: nginx uses configuration in "location ~* \.(...)$" which
has no root explicitly set, and therefore root is inherited from
server/http level (or compiled-in default).
本文探讨了Nginx中配置location指令导致静态资源请求失败的问题,并提供了修正方案。通过调整root路径设置,确保了静态文件如图片、CSS及JS等能够被正确加载。
458

被折叠的 条评论
为什么被折叠?



