重复执行Cache-Control标头;有效还是无效? (Nginx) [英] Cache-Control headers repeated; valid or not? (Nginx)

查看:286
本文介绍了重复执行Cache-Control标头;有效还是无效? (Nginx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Nginx中有一个配置如下的资源:

I've got a resource in my Nginx that is configured like this:

location ~ foo\.js$ {
    add_header Cache-Control public;
    expires 1d;
}

如果我用Firebug打开它,然后查看它显示的标题:

If I open this with Firebug and look at the headers it shows this:

Cache-Control   max-age=86400, public

该站点正在使用HTTPS,所以我想确保它正确无误,因为显然,除非它的max-age> 0 AND public,否则浏览器不会缓存它. 参见此

The site is using HTTPS so I want to make sure I get it right because apparently browsers don't cache it unless it's max-age>0 AND public. See this

但是当我使用curl -Ik https://...时,我的Nginx会发生什么,那就是:

But what happens with my Nginx when I use curl -Ik https://... is that it says:

...
Expires: Sat, 22 Jan 2011 18:23:36 GMT
Cache-Control: max-age=86400
Cache-Control: public
...

它重复Cache-Control标头!显然,Firebug不在乎.但这是对的吗?

It repeats the Cache-Control header! Clearly Firebug doesn't mind. But is it right?

是否有更好的方法来将ExpiresCache-Control(使用public)设置为仅两行?

Is there a perhaps a better way to set Expires and Cache-Control (with public) in one just two lines?

推荐答案

是的,它等效于使用多个Cache-Control标头.

Yes, it's valid and equivalent to use multiple Cache-Control headers.

根据 HTTP 1.1规范:

具有多个消息标题字段 相同的字段名称可能出现在 一条消息,当且仅当整个 该标头字段的字段值是 定义为以逗号分隔的列表 [即#(values)].一定有可能 组合多个标题字段 变成一个字段名称:字段值" 对,而不改变语义 通过附加每个 随后的字段值到第一个字段, 每个都用逗号分隔.

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.

由于方式,很容易验证此规定是否适用于Cache-Control标头它已定义:

Cache-Control ="Cache-Control":" 1#cache-directive

Cache-Control = "Cache-Control" ":" 1#cache-directive

要了解如何解释以上内容,请参阅规范的符号约定. 1#表示以逗号分隔的一个或多个列表".

To understand how to interpret the line above, see the spec's notational conventions. The 1# means "a comma-separated list of one or more".

这篇关于重复执行Cache-Control标头;有效还是无效? (Nginx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆