Apache mod_deflate does not compress json output

I followed all the steps in several tutorials to enable mod_deflate in Apache, but I still don’t see compression (in Fiddler) when I issue json requests (via a PHP script) on my local web server. Compression is not required for my browser on localhost, but my machine will periodically be exposed to 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 at startup: header('Content-Type: application/json');

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

And this is the relevant section from httpd.conf about 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 is returned without compression. I restarted Apache after every .conf change.

Any suggestions are very welcome!

+7
source share
1 answer

Wild hunch here ... can be added as a new line in config:

 AddOutputFilter DEFLATE php 

or add

 application/x-httpd-php 

to the end of the AddOutputFilterByType drop-down list.

+11
source

All Articles