【问题标题】:What does `expires -1` mean in NGINX `location` directive?NGINX `location` 指令中的`expires -1` 是什么意思?
【发布时间】:2015-09-04 11:02:38
【问题描述】:

鉴于下面的示例location-1expires 意味着什么?这是否意味着“永不过期”或“永不缓存”?

# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
  expires -1;
  access_log logs/static.log;
}

https://github.com/h5bp/server-configs-nginx/blob/b935688c2b/h5bp/location/expires.conf

【问题讨论】:

    标签: caching nginx cache-control


    【解决方案1】:

    根据nginx manual,该指令将ExpiresCache-Control HTTP 标头添加到响应中。

    -1 表示这些标头设置为:

    Expires: 当前时间减去 1 秒

    Cache-Control: no-cache

    所以总而言之,它指示浏览器不要缓存文档。

    【讨论】:

      【解决方案2】:

      如果使用expires -1,则意味着这些页面永远不会被缓存。 expire 指令指示浏览器在一定时间后(或在特定时间)使文件缓存过期。如果给定负值,则没有缓存。

      【讨论】:

      • 这不是真的,它与nginx本身的缓存无关。它只是为浏览器添加了一个标题 - nginx.org/en/docs/http/ngx_http_headers_module.html#expires
      • 更正它是浏览器缓存 - 我的错误。我已经更新了我的答案。我不确定您的单独答案添加了什么-本质上将 expire 设置为负值意味着没有缓存。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      相关资源
      最近更新 更多