【发布时间】:2015-10-31 21:11:04
【问题描述】:
我想为图像实现浏览器缓存的网站之一 virtual.conf 上有这个特定的 server {} 块
server {
listen 80;
server_name www.example.net example.net;
location / {
root /var/www/example.net/public_html;
index index.html index.htm index.php;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/example.net/public_html;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/example.net/public_html;
}
location ~* \.(jpg|jpeg|png|gif)$ {
expires 180d;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www/example.net/public_html;
error_log /var/www/example.net/public_html/error.log error;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
通常这个指令
location ~* \.(jpg|jpeg|png|gif)$ {
expires 180d;
}
应注意在用户端缓存图像。但是当我访问时 我网站上的一张图片我找不到 404。我不知道为什么会这样。
是的。添加指令后,我重新加载/重新启动了 nginx。
图像位于以下子文件夹中:
example.net/images/dir1/user_photos/photo.jpg
或
example.net/images/dir1/user_photos/photo.jpg
任何帮助将不胜感激。 谢谢。
【问题讨论】:
-
我有同样的问题 - 如果我删除指令,它会显示文件,如果我再次添加它,然后过一段时间我再次遇到 404 问题。以下是我的问题的详细信息:stackoverflow.com/questions/33495113/…
-
你能解决这个问题吗?我在 Digital Ocean 上有同样的问题。请告诉我你是如何让它工作的。
标签: nginx browser-cache