缓存控制头重复;有效与否?(Nginx) [英] Cache-Control headers repeated; valid or not? (Nginx)

查看:17
本文介绍了缓存控制头重复;有效与否?(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 标头,因为 如何它的定义:

It's easy to verify that this provision applies to the Cache-Control header because of how it's defined:

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".

这篇关于缓存控制头重复;有效与否?(Nginx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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