我想在 Apache 中的某个 VirtualHost 上仅使用 HTTP 1.0。这样做的原因是,我使用 CloudFlare,并且我的应用程序需要 HTTP 响应中的 Content-Length 标头。但是,如果使用 HTTP 1.0 作为协议,CloudFlare 只会转发 Content-Length 标头(请参阅此支持凭单:https://support.cloudflare.com/hc/en-us/requests/527063)。
我的问题是,如何在 Apache 中轻松设置某个 VirtualHost 来实现此目的(强制使用 HTTP 1.0 作为协议)?我是否在 sites-available 配置文件中使用类似 SetEnv 的东西?或者,我使用 HTTP 1.1 协议,但在标头中发送 HTTP 1.0 作为协议?
谢谢。
答案1
从https://www.safaribooksonline.com/library/view/apache-the-definitive/0596002033/re249.html这里是使用force-response-1.0
变量的例子BrowserMatch
。
#
# The following directives modify normal HTTP response behavior.
# The first directive disables keepalive for Netscape 2.x and browsers that
# spoof it. There are known problems with these browser implementations.
# The second directive is for Microsoft Internet Explorer 4.0b2
# which has a broken HTTP/1.1 implementation and does not properly
# support keepalive when it is used on 301 or 302 (redirect) responses.
#
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
#
# The following directive disables HTTP/1.1 responses to browsers which
# are in violation of the HTTP/1.0 spec by not being able to grok a
# basic 1.1 response.
#
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
官方文档位于http://httpd.apache.org/docs/2.4/env.html#special哪一个州
力响应-1.0
这会强制对发出 HTTP/1.0 请求的客户端进行 HTTP/1.0 响应。它最初是作为 AOL 代理问题的结果而实施的。某些 HTTP/1.0 客户端在收到 HTTP/1.1 响应时可能无法正确运行,这可用于与它们进行互操作。