V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
coolicer
V2EX  ›  NGINX

Nginx的缓存去不掉怎么办?

  •  
  •   coolicer · 2013-11-30 15:12:49 +08:00 · 8806 次点击
    这是一个创建于 3803 天前的主题,其中的信息可能已经有所发展或是发生改变。
    location ~ .*\.(js|css)?$ {
    expires 1h;
    }

    后来看到有这一行,去掉,重启过也没用。CSS加载都是上一次的,怎么刷都不更新。用的是thinkphp,我猜是服务器的问题,删掉内容是可以看到CSS文件是空的,随便打的字,显示的就是上一次的内容。神了!
    第 1 条附言  ·  2013-11-30 16:08:39 +08:00
    Stackoverflow上解决了

    I had the exact same problem - I was running my nginx in virtualbox. I did not have caching turned on. But looks like sendfile was set to on in nginx.conf and that was causing the problem. @kolbyjack mentioned it above in the comments -

    when i turned off sendfile - it worked fine.
    第 2 条附言  ·  2013-11-30 16:09:20 +08:00
    我也是vbox里的ubuntu,随便问一句。sendfile关掉有什么影响
    13 条回复    2016-02-03 16:00:02 +08:00
    coolicer
        1
    coolicer  
    OP
       2013-11-30 15:19:25 +08:00
    coolicer
        2
    coolicer  
    OP
       2013-11-30 15:19:48 +08:00
    9hills
        3
    9hills  
       2013-11-30 15:46:08 +08:00
    在静态资源后面加
    ?v=xxx

    这样每次update,都可以改变这个version,这样就不会受缓存困扰了
    9hills
        4
    9hills  
       2013-11-30 15:48:46 +08:00
    不过不嫌麻烦的话最好是

    main.css -> main.$version.css

    当然server端可以吧main.$version.css rewrite到容易实现的 main.css?v=xxx

    这个主要是因为许多proxy不会cache 带「?」的URL,所以能不带就不带
    coolicer
        5
    coolicer  
    OP
       2013-11-30 15:53:47 +08:00
    @9hills 没截到图给你看,加了也一样。我真的不知道是什么问题。
    cst4you
        6
    cst4you  
       2013-11-30 17:15:24 +08:00
    expires 只是给你HTTP header加个expires的头而已, 跟nginx没有关系
    缓存了的是浏览器
    coolicer
        7
    coolicer  
    OP
       2013-11-30 17:48:20 +08:00
    @cst4you 不知道你说什么
    faceair
        8
    faceair  
       2013-11-30 19:07:11 +08:00
    @cst4you 的意思是:浏览器保存的css,不是nginx,请清理浏览器缓存
    zhujinliang
        9
    zhujinliang  
       2013-11-30 19:24:01 +08:00
    貌似我也遇到过类似的问题。实际情况是nginx缓存了数据,当你本地磁盘的文件更改后,nginx却并没有理会,仍从旧的缓存直接发送数据而不读取磁盘。

    谢楼主分享,以后注意一下sendfile选项。
    VYSE
        10
    VYSE  
       2013-11-30 20:47:42 +08:00
    关掉会导致STATIC FILE走CPU而不是DMA。
    PRODUCTION环境建议nginx reload,只会reset worker进程
    akira
        11
    akira  
       2013-11-30 22:07:23 +08:00
    你应该清空你浏览器的缓存。
    julyclyde
        12
    julyclyde  
       2013-12-01 11:03:17 +08:00
    @9hills 你说的那cache都是古代的了……
    v5mark
        13
    v5mark  
       2016-02-03 16:00:02 +08:00
    神了,我也是这个问题, vb+nginx 。就猜是不是 sendfile 的问题。。果然如此啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1863 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 16:22 · PVG 00:22 · LAX 09:22 · JFK 12:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.