如何在 Apache 中对 mod_jk 代理应用程序服务器的某些响应标头禁用压缩
我有一个 tomcat 服务器(通过 mod_jk)配置为通过 Apache Httpd 服务器工作。
Apache Httpd 服务器压缩(通过 mod_deflate)发送到浏览器的所有文本/html。
一些jsp页面是交互式的并且长时间运行,即在执行期间显示进度或日志。 如果打开压缩,这些页面上的所有文本都会在页面执行结束时出现。
我希望能够在 JSP 页面中设置一些响应标头,例如
<% response.setHeader("X-Compress", "0"); %>
在 Apache Httpd 中这必须导致禁用压缩, 例如通过设置 no-gzip 环境变量。
也许还有其他方法?
I have a tomcat server configured (by mod_jk) to work through Apache Httpd server.
Apache Httpd server compresses (by mod_deflate) all text/html sent to browser.
Some jsp pages are interactive and long running, i.e. display progress or log during execution.
If compression turned on, all text on these pages comes at the end of page execution.
I would like to have ability to set in JSP page some response header, e.g.
<% response.setHeader("X-Compress", "0"); %>
And in Apache Httpd this must result in disabling compression,
for example by setting no-gzip environment variable.
Maybe there is other approaches?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用 mod_layout 向页面添加标题。当页面通过 mod_jk 来自 tomcat 时会出现问题。它在 gzip 压缩的二进制代码之前添加纯文本标头,从而损坏 gz 文件。它的文档似乎很差,但除了压缩问题之外,它做得很好。
很遗憾,
对我不起作用。
也没有:
这确实有效:
启用 mod_headers
向您的 VirtualHost 添加一行
<块引用>
RequestHeader 未设置 Accept-Encoding
有关 mod_headers 的更多信息:
http://httpd.apache.org/docs/2.0/mod/mod_headers.html
我的 mod_layout 来自 Ubuntu 的包管理器,但它也在这里:
htt p://download.tangent.org/
这是我第一次读到 mod_layout 的页面:
http://www.linuxjournal.com/article/4334
I am using mod_layout to add a header to the page. It has issues when the page comes from tomcat through mod_jk. It adds the plain text header before the gzipped binary code, corrupting the gz file. It seems to have very poor documentation, but does a fine job other than the compression problem.
Unfortunately,
did not work for me.
Neither did:
This did work:
enable mod_headers
add a line to your VirtualHost
More about mod_headers:
http://httpd.apache.org/docs/2.0/mod/mod_headers.html
My mod_layout came from Ubuntu's package manager, but it is also here:
htt p://download.tangent.org/
And here is the page where I first read about mod_layout:
http://www.linuxjournal.com/article/4334
我认为通过 HTTP 标头不可能,因为该标头仅用于告诉客户端如何行为。但是你必须告诉阿帕奇。
但可以使用 .htaccess 文件禁用它(如果可以的话):
I don't think it is possible via HTTP header, for this header is only used for telling the client how to behave. You however have to tell apache.
But can disable it using a .htaccess file, if that is an option:
在最近的设置上进行了测试(Apache httpd 2.2.16、Tomcat 6.0.29、mod_jk 1.2.30、tcnative-1.dll)。
不存在这样的问题(使用Apache httpd 2.0.x可能仍然存在)。
jsp中使用response.flushBuffer()或out.flush()时,发送flush包
通过 mod_jk 到 Apache。这反过来又创建了由 deflate 接收的 APR 刷新桶
模块并强制其将压缩缓冲区刷新到浏览器。
因此,响应是压缩且交互式的。
PS 但是,我已经创建了相关补丁,它对来自应用程序服务器的 X-nogzip 标头做出反应。设置为 X-nogzip: 1 以禁用压缩。
http:// huksley.sdot.ru/wp-content/uploads/2010/09/mod_jk-1.2.30-x-nogzip-patch.zip
Tested on recent setup (Apache httpd 2.2.16, Tomcat 6.0.29, mod_jk 1.2.30, tcnative-1.dll).
There is no such problem (it may still exists using Apache httpd 2.0.x).
When using response.flushBuffer() or out.flush() in jsp, flush packet is sent
to Apache via mod_jk. This in turn creates APR flush bucket which is received by deflate
module and forces it to flush compression buffer to browser.
So response is COMPRESSED AND INTERACTIVE.
P.S. However, I`have created relevant patch which reacts on X-nogzip header from application server. Set to X-nogzip: 1 to disable compression.
http://huksley.sdot.ru/wp-content/uploads/2010/09/mod_jk-1.2.30-x-nogzip-patch.zip