如何在 Apache 中对 mod_jk 代理应用程序服务器的某些响应标头禁用压缩

发布于 2024-09-13 04:21:50 字数 396 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

桃扇骨 2024-09-20 04:21:50

我正在使用 mod_layout 向页面添加标题。当页面通过 mod_jk 来自 tomcat 时会出现问题。它在 gzip 压缩的二进制代码之前添加纯文本标头,从而损坏 gz 文件。它的文档似乎很差,但除了压缩问题之外,它做得很好。

很遗憾,

重写规则。 - [E=no-gzip:1]

对我不起作用。

也没有:

AddOutputFilterByType DEFLATE 文本/html 文本/纯文本/xml

这确实有效:

  1. 启用 mod_headers

  2. 向您的 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,

RewriteRule . - [E=no-gzip:1]

did not work for me.

Neither did:

AddOutputFilterByType DEFLATE text/html text/plain text/xml

This did work:

  1. enable mod_headers

  2. add a line to your VirtualHost

    RequestHeader unset Accept-Encoding

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

用心笑 2024-09-20 04:21:50

我认为通过 HTTP 标头不可能,因为该标头仅用于告诉客户端如何行为。但是你必须告诉阿帕奇。

但可以使用 .htaccess 文件禁用它(如果可以的话):

RewriteRule . - [E=no-gzip:1]

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:

RewriteRule . - [E=no-gzip:1]
一抹苦笑 2024-09-20 04:21:50

在最近的设置上进行了测试(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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文