难道你们没有遇到 mac + virtualbox 下图片的缓存bug吗?

2013-01-19 19:18:53 +08:00
 sdjl
我想, 这里应该也有一些朋友像我们一样使用mac但是开发环境是linux吧?

如果你使用virtualbox虚拟机, 并通过虚拟机下的apache或者nginx来访问图片, 那么就会遇到一个bug(我们的文件放到mac系统下, 并共享给linux)

就是, 当你改动图片内容时, 你的浏览器拿到的内容依然是以前的版本, 而且不管是mac下的浏览器还是虚拟机下的都一样

这个问题一直困扰我们许久, 重启nginx也没用, 之前我们的解决办法是通过把图片重定向让它去访问mac下的nginx, 这样就可以临时解决了, 但是这个方法却很笨, 会引出许多麻烦事情

今天下午, 我开始不断的尝试解决这个问题, 后来突然一个想法就搞定了

那就是, 不使用nginx提供静态文件访问, 直接把请求转发给一个python程序, 在python程序中:

return open(file).read()

就搞定了, 速度分享
3025 次点击
所在节点    程序员
6 条回复
loading
2013-01-19 19:55:06 +08:00
按shift刷新也不行么?这是浏览器缓存问题吧…
sdjl
2013-01-19 20:04:18 +08:00
@loading 不是浏览器的缓存问题, 清空缓存没用, 换浏览器也没用
lemon20120901
2013-01-20 10:58:02 +08:00
VirtualBox’s Shared Folders 对 sendfile() 支持不完善

Apache
EnableSendfile off
Nginx
sendfile off;
问一下,,楼主用的是vagrant吗。
sNullp
2013-01-20 11:10:42 +08:00
http://wiki.nginx.org/Pitfalls

VirtualBox

If this does not work, and you're running nginx on a virtual machine in VirtualBox, it may be sendfile() that is causing the trouble. Simply comment out the sendfile directive or set it to "off". The directive is most likely found in your nginx.conf file.

sendfile off;
sdjl
2013-01-20 13:19:13 +08:00
@sNullp
@lemon20120901 我用的是virtualbox + debain

sendfile 好像是尝试过的, 不管用, 一会我放到nginx.conf里面试一下
sdjl
2013-01-20 20:39:19 +08:00
@lemon20120901
@sNullp

刚才测试了一下, 在nginx.conf中把sendfile改为off确实可以, 感谢了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/58118

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX