“总是”之间的区别是什么?和“onsuccess”在Apache的Header配置? [英] What is the difference between "always" and "onsuccess" in Apache's Header config?

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

问题描述

我有一个网站,其中虚拟主机在 / etc / apache2 / sites-enabled / 中定义,标头设置为始终这样的选项:

I have a website where virtual hosts are defined in /etc/apache2/sites-enabled/ with a header being set with the always option like this:

Header always set X-Frame-Options DENY

如果我现在在网站的根目录中使用 .htaccess 设置相同的标题文件夹,但没有总是然后在服务器的响应中返回两次标题。

If I now set the same header using .htaccess in the web site's root folder, but without always then the header is returned twice in the server's response.

<$ c中的设置$ c> .htaccess (等等):

Header set X-Frame-Options DENY

服务器的回复:

HTTP/1.1 200 OK
Date: Mon, 02 May 2016 16:02:29 GMT
Server: Apache/2.4.10 (Debian)
X-Frame-Options: DENY
Cache-Control: no-cache, no-store, must-revalidate, private
Pragma: no-cache
X-XSS-Protection: 1
X-Content-Type-Options: nosniff
Last-Modified: Mon, 02 May 2016 15:03:42 GMT
Accept-Ranges: bytes
Content-Length: 0
X-Frame-Options: DENY
X-XSS-Protection: 1
X-Content-Type-Options: nosniff
Cache-Control: no-cache, no-store, must-revalidate, private
Pragma: no-cache
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

Apache文档说没有始终选项使用默认值 onsuccess 。但他们也说...... onsuccess的默认值不会限制对2xx状态代码的响应的操作...... http://httpd.apache.org/docs/current/en/mod/mod_headers.html#header )。

The Apache docs say that without the always option the default value of onsuccess is used. But they also say that "... the default value of onsuccess does not limit an action to responses with a 2xx status code..." (http://httpd.apache.org/docs/current/en/mod/mod_headers.html#header).

但如果我不添加总是,那么像301和404这样的错误页面就不会有标题集。另一方面,如果我添加总是,那么如果我使用默认值(即 onsuccess c> .htaccess 中的$ c>。正如文档所述:在某些情况下重复使用这两个条件的指令是有意义的,因为对于现有标题总是不是onsuccess的超集。设置标题两次并不总是对HTTP响应有效,请参阅 https://stackoverflow.com/a/4371395/641481 。所以我想自然地避开它。

But if I don't add always, then error pages like 301s and 404s will not have the header set. On the other hand, if I do add always then the headers might be set twice if I do use the default value (i.e. onsuccess) in .htaccess. As the docs state: "repeating this directive with both conditions makes sense in some scenarios because always is not a superset of onsuccess with respect to existing headers". Setting headers twice is not always valid for an HTTP response, see https://stackoverflow.com/a/4371395/641481. So I want to avoid it, naturally.

我现在的问题是:我应该什么时候使用 onsuccess (即默认值)和总是?我必须承认,即使经过阅读Apache文档几次,我也不完全理解这一点。实际上似乎总是使用总是导致正确/预期的行为。

My question now is: When exactly should I use onsuccess (i.e. the default value) and when always? I must admit that even after reading through the Apache docs a couple of times I do not exactly understand this. Pragmatically it seems that always using always leads to the correct/expected behaviour.

我也不明白为什么Apache如果在始终 onsuccess 中设置,则将标题写入两次。这对我来说似乎不对,但是必须有一个很好的理由,因为我认为Apache-devs比我对HTTP知道的要多得多; - )

I also do not understand why Apache writes the header twice if it is set in always and onsuccess. It seems wrong to me, but there must be a good reason for this, since I assume the Apache-devs know a lot more than I do about HTTP ;-)

推荐答案

这只是部分答案,因为它不包括 onsuccess 属性。它基于在Ubuntu 14操作系统上运行的apache 2.4.7的经验。希望它可以帮助你。

This is only a partial answer since it does not cover the onsuccess attribute. It is based on experiences using apache 2.4.7 running on an Ubuntu 14 os. Hope it helps you along.

设置参数,没有属性,到标题指令通过强制参数标题集成为唯一的始终属性一个交付。如果同一指令出现在目录中,即基于文件系统的.htaccess文件,则它优先于与该目录相关的虚拟主机定义文件中指出的同一指令。如果另外注意属性始终,则它具有将同一指令的任何,相同或不同的符号添加到服务器答案而不是覆盖/替换它的效果。

The pure set parameter, without attributes, to the Header directive overwrites any always attribute by forcing the argument to Header set to be the only one delivered. If the same directive appears in a directory, i.e. file system based .htaccess file it has precedence over the same directive noted in a virtual host definition file related to that directory. If the attribute always is noted additionaly, it has the effect that any, equal or different, notation of the same directive is added to the server answer instead of overwriting/replacing it.

可能 onsuccess 属性,我很遗憾没有时间去探索,可能会被处理为类似于始终属性。

Probably the onsuccess attribute, which i unfortunately do not have the time to explore now, may be handled similar as the always attribute.

这篇关于“总是”之间的区别是什么?和“onsuccess”在Apache的Header配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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