Apache mod_deflate 不压缩 json 输出
我已按照多个教程中的所有步骤在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里大胆猜测...也许添加为配置中的新行:
或添加
到现有的 AddOutputFilterByType 列表的末尾。
Wild guess here... maybe add as a new row in the config:
or add
to the end of your exising AddOutputFilterByType list.