V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sdjl
V2EX  ›  程序员

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

  •  
  •   sdjl · 2013-01-19 19:18:53 +08:00 · 3018 次点击
    这是一个创建于 4114 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想, 这里应该也有一些朋友像我们一样使用mac但是开发环境是linux吧?

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

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

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

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

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

    return open(file).read()

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

    Apache
    EnableSendfile off
    Nginx
    sendfile off;
    问一下,,楼主用的是vagrant吗。
    sNullp
        4
    sNullp  
       2013-01-20 11:10:42 +08:00   ❤️ 1
    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
        5
    sdjl  
    OP
       2013-01-20 13:19:13 +08:00
    @sNullp
    @lemon20120901 我用的是virtualbox + debain

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

    刚才测试了一下, 在nginx.conf中把sendfile改为off确实可以, 感谢了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3348 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:02 · PVG 20:02 · LAX 05:02 · JFK 08:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.