Apache:“Header always set”之间的区别和“标题集”? [英] Apache: difference between "Header always set" and "Header set"?

查看:393
本文介绍了Apache:“Header always set”之间的区别和“标题集”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 标题总是设置和<$之间有什么区别? c $ c> Apache中的标头集?

  2. 也就是说,始终关键字的变化是什么设置标题的情况?

  3. 我应该始终使用设置标题

  4. 有没有理由不这样做?

  1. What is the difference between Header always set and Header set in Apache?
  2. That is, what does the always keyword change about the circumstances under which the header is set?
  3. Should I always set my headers using always?
  4. Is there any reason not to?



背景



I已经看过......

Background

I've seen...

Header always set X-Frame-Options DENY

...以及......

...as well as...

Header always set Access-Control-Allow-Headers "*"

...我有时会听到始终关键字的存在确保标题已正确设置,或者包含总是更好关键字一般。但是,我从未找到为什么的明确,明确的答案。

...and I sometimes hear that the presence of the always keyword ensures that the header is properly set, or that it's simply better to include the always keyword in general. However, I have never found a clear, definitive answer for why that is the case.

我已经检查了 Apache文档 mod_headers ,其中只是简单地提到总是


当你的行动是现有标题的一个功能时,您可能需要指定始终的条件,具体取决于设置原始标头的内部表。始终对应的表用于本地生成的错误响应以及成功的响应。另请注意,在某些情况下重复使用这两个条件的指令是有意义的,因为对于现有标题,始终不是onsuccess的超集:

When your action is a function of an existing header, you may need to specify a condition of always, depending on which internal table the original header was set in. The table that corresponds to always is used for locally generated error responses as well as successful responses. Note also that repeating this directive with both conditions makes sense in some scenarios because always is not a superset of onsuccess with respect to existing headers:


  • 您正在为本地生成的非成功(非2xx)响应添加标头,例如重定向,在这种情况下,只会在最终响应中使用与always相对应的表。

  • 您正在修改或删除由CGI脚本生成的标头,在这种情况下,CGI脚本位于对应于始终而不是默认表中的表中。

  • 您是修改或删除某些服务器生成的标头,但默认的onsuccess条件下找不到该标头。

据我所知,这意味着 Header set 确保即使在非200页面上也设置了标头。但是,使用 Header set 设置的HTTP标头似乎总是适用于我的404页面等等。我在这里误解了什么吗?

As far as I can tell, this means that Header set always ensures that the header is set even on non-200 pages. However, my HTTP headers set with Header set have always seemed to apply just fine on my 404 pages and such. Am I misunderstanding something here?

FWIW,我发现了SO帖子,如 总是之间的区别是什么?和onsuccess在Apache的Header配置中?,但唯一的答案并没有真正为我解释清楚。

FWIW, I've found SO posts like What is the difference between "always" and "onsuccess" in Apache's Header config?, but the only answer there didn't really explain it clearly for me.

非常感谢,

Caleb

Thanks very much,
Caleb

推荐答案


在Apache中设置Header始终设置和Header之间有什么区别?

What is the difference between Header always set and Header set in Apache?

正如手册中引用的位所示,如果没有总是,您的添加内容只会在成功的回复中显示。

As the quoted bit from the manual says, without 'always' your additions will only go out on succesful responses.

但这也包括通过mod_proxy和其他大致类似代理的类似处理程序的成功转发错误。是什么生成了您发现不同意手册的404?本地文件上的404肯定与引用位描述的行为相同。

But this also includes "successfully" forward errors via mod_proxy and perhaps other similar handlers that roughly act like proxies. What generates your 404s that you found to disagree with the manual? A 404 on a local file certainly behaves as the quoted bit describes.


也就是说,always关键字在哪些情况下会发生变化标头已设置?

That is, what does the always keyword change about the circumstances under which the header is set?

Apache的API保留了与每个请求,标头和err_headers关联的两个列表。如果服务器遇到处理后者请​​求的错误,则不使用前者。

Apache's API keeps two lists associated with each request, headers and err_headers. The former is not used if the server encounters an error processing the request the latter is.


我应该始终使用always设置标头吗? / p>

Should I always set my headers using always?

这取决于它们的重要性。假设您设置的Cache-Control标头与您预期为某些资源提供的服务相关。现在让我们说你实际上是在服务400或502.你可能不希望缓存!

It depends on their significance. Let's say you were setting Cache-Control headers that were related to what you had expected to serve for some resource. Now let's say you were actually serving something like a 400 or 502. You might not want that cached!


有什么理由不这样做吗?

Is there any reason not to?

见上文。

- / -

-/-

手册中还有一点没有引用,它解释了错误代码的代理或CGI,但没有解释Apache正在生成错误响应的那个:

There is also a bit in the manual you did not quote which explains the proxy or CGI of an error code but not for one which Apache is generating an error response for:


可选条件参数确定此指令将针对哪个
响应头的内部表。尽管
名称,onsuccess的默认值不会将操作限制为带有2xx状态代码的
响应。

The optional condition argument determines which internal table of responses headers this directive will operate against. Despite the name, the default value of onsuccess does not limit an action to responses with a 2xx status code.

例如,当CGI成功代理或生成
请求时,仍然会使用在此条件下设置的标头,即使它们是
生成了失败的状态代码。

Headers set under this condition are still used when, for example, a request is successfully proxied or generated by CGI, even when they have generated a failing status code.

这篇关于Apache:“Header always set”之间的区别和“标题集”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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