Apache mod_deflate 不压缩 json 输出

发布于 2024-12-28 20:40:28 字数 1069 浏览 3 评论 0原文

我已按照多个教程中的所有步骤在 Apache 中启用 mod_deflate,但当我向本地 Web 服务器发出 json 请求(通过 PHP 脚本)时,我仍然没有看到压缩(在 Fiddler 中)。我的浏览器不需要压缩到本地主机,但我的机器会定期通过慢速 VPN 暴露,所以我想使用它。

来自 httpd.conf:

LoadModule deflate_module module/mod_deflate.so (未注释掉)

mod_deflate.so 存在于 Apache2/modules

PHP 脚本在运行时立即设置以下标头: header('Content -Type: application/json');

application/json 存在于 Apache2/conf/mime.types 中

这是 httpd.conf 中关于 mime 类型的相关部分应该被压缩:

Alias /mapguide "C:/Program Files/OSGeo/MapGuide/Web/www/"
<Directory "C:/Program Files/OSGeo/MapGuide/Web/www/">
  AllowOverride All
  Options All -Indexes
  Order allow,deny
  Allow from all

...

  # Content compression
  AddType text/javascript js jgz
  AddOutputFilterByType DEFLATE text/javascript application/json text/html

  RewriteEngine on
  RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
</Directory>

当我向服务器发出请求时,请求标头包括 Accept-Encoding: gzip, deflate ,但响应返回时未压缩。每次 .conf 更改后我都会重新启动 Apache。

非常欢迎任何建议!

I've followed all the steps in multiple tutorials to enable mod_deflate in Apache but I'm still not seeing compression (in Fiddler) when I issue requests for json (via PHP script) to my local web server. Compression isn't necessary for my browser to localhost but my machine will be periodically exposed over a slow VPN so I would like to use it.

from httpd.conf:

LoadModule deflate_module modules/mod_deflate.so (not commented-out)

mod_deflate.so exists in Apache2/modules

PHP scripts immediately set the following header when run: header('Content-Type: application/json');

application/json exists in Apache2/conf/mime.types

And this is the relevant section from httpd.conf on the mime-types that should be compressed:

Alias /mapguide "C:/Program Files/OSGeo/MapGuide/Web/www/"
<Directory "C:/Program Files/OSGeo/MapGuide/Web/www/">
  AllowOverride All
  Options All -Indexes
  Order allow,deny
  Allow from all

...

  # Content compression
  AddType text/javascript js jgz
  AddOutputFilterByType DEFLATE text/javascript application/json text/html

  RewriteEngine on
  RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
</Directory>

When I issue a request to the server the request headers include Accept-Encoding: gzip, deflate, but the response comes back uncompressed. I have restarted Apache after every .conf change.

Any suggestions very welcome!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

追风人 2025-01-04 20:40:28

这里大胆猜测...也许添加为配置中的新行:

AddOutputFilter DEFLATE php

或添加

application/x-httpd-php

到现有的 AddOutputFilterByType 列表的末尾。

Wild guess here... maybe add as a new row in the config:

AddOutputFilter DEFLATE php

or add

application/x-httpd-php

to the end of your exising AddOutputFilterByType list.

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