How could I create a simple content handler for apache .gz gzip content. I want it to uncompress say http://localhost/doc/FAQ/Linux-FAQ.gz and send it to the browser as plain te
cat /etc/apache2/mods-enabled/mime.conf | head -n 30
<IfModule mod_mime.c>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig /etc/mime.types
#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have
# nothing to do with the FancyIndexing customization directives above.
#
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
AddEncoding x-bzip2 .bz2
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-bzip2 .bz2
I've used something like this before for js/css files (I modified the below to match your needs). Add this to your virtualhost entry:
Alias /doc/ "/usr/share/doc/"
Alias local.doc "/usr/share/doc/"
<Directory /usr/share/doc>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
AddEncoding gzip gz
<FilesMatch "\.gz$">
ForceType text/plain
Header set Content-Encoding: gzip
</FilesMatch>
</Directory>
Updated above to match your code
In ubuntu ensure that Headers module is enabled
$ sudo a2enmod headers
$ sudo a2enmod deflate
$ sudo apache2ctl restart
Update2: Realized that "AddEncoding gzip gz" was missing.. otherwise, file kept trying to download.
Update3: Added apache module deflate install command. Here's my deflate.conf:
<IfModule mod_deflate.c>
# these are known to be safe with MSIE 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml
# everything else may cause problems with MSIE 6
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
AddOutputFilterByType DEFLATE application/rss+xml
</IfModule>
You could first try with some other type of file (e.g. a css file). Example:
cd /usr/share/doc
cat ".styles { width: 50px; }" > test.css
gzip -c test.css > test.css.gz
Add this to your virtualhost:
<FilesMatch "\.css\.gz$">
ForceType text/css
Header set Content-Encoding: gzip
</FilesMatch>
Test http://127.0.0.1/doc/test.css and http://127.0.0.1/doc/test.css.gz and see what result you get.