简体   繁体   English

Apache mod_deflate不压缩json输出

[英]Apache mod_deflate not compressing json output

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

from httpd.conf: 来自httpd.conf:

LoadModule deflate_module modules/mod_deflate.so (not commented-out) LoadModule deflate_module modules/mod_deflate.so (未注释掉)

mod_deflate.so exists in Apache2/modules mod_deflate.so存在于Apache2 / modules中

PHP scripts immediately set the following header when run: header('Content-Type: application/json'); 运行时,PHP脚本会立即设置以下标头: header('Content-Type: application/json');

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

And this is the relevant section from httpd.conf on the mime-types that should be compressed: 这是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>

When I issue a request to the server the request headers include Accept-Encoding: gzip, deflate , but the response comes back uncompressed. 当我向服务器发出请求时,请求标头包括Accept-Encoding: gzip, deflate ,但响应返回未压缩。 I have restarted Apache after every .conf change. 每次.conf更改后我都重启了Apache。

Any suggestions very welcome! 任何建议都非常欢迎!

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. 到您现有的AddOutputFilterByType列表的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM