Apache mod_deflate未压缩json输出


Apache mod_deflate not compressing json output

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

来自httpd.conf:

LoadModule deflate_module modules/mod_deflate.so(未注释)

mod_deflate.so存在于Apache2/模块中

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

application/json存在于Apache2/conf/meme.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。

欢迎提出任何建议!

在这里胡乱猜测。。。可能在配置中添加新行:

AddOutputFilter DEFLATE php

或添加

application/x-httpd-php

到当前AddOutputFilterByType列表的末尾。