# Apache: serving gzip'd files

## epretorious

I've been playing around with my freshly minted installation of Apache 1.3.27 and noticed that the contents of /usr/share/doc are available (http://localhost/doc/) but all of the documentation is gzip'd.

Is there any way to have Apache gunzip the files [on-the-fly] for display in the browser?

----------

## devon

You would write a script that uses zcat to uncompress-and-cat the files.

----------

## epretorious

 *devon wrote:*   

> You would write a script that uses zcat to uncompress-and-cat the files.

 

Nah - There's got to be a way!   :Shocked: 

It would only make sense that Apache can decompress .gz files on the fly since mod_autoindex is configured (using the ReadmeName value) to append any README files at the end of directory indexes (if MultiViews and FancyIndexing are enabled) [u]and[\u] all of the README files in /usr/share/doc/ are gzip'd.

----------

## uzik

I saw a configuration option that told apache to auto gunzip files

before sending them out. You just gzip your web pages and apache

takes care of the rest. Sorry I don't remember more about it.

----------

## skunkworx

Dusting off an old thread here...

I came across this thread when looking to see if any Gentoo'ers had worked with this Apache module that is supposed to be able to serve gzipped content, unzipping it on the fly only to servers that need it.  Might be useful if you're still looking for something.

----------

## Jaminadi

Well, This is an old posting, but I wanted to browse my documents in /usr/share/doc

After a bit more research I found what most people already know.  You can use a Ext filter in apache2 to do these.

For example, I wanted to convert .html.gz into .html.  I added the following

```

ExtFilterDefine gz-to-html mode=output \

intype=application/x-gzip-html outtype=text/html \

cmd="/bin/gunzip -c -"

AddType application/x-gzip-html .html.gz

```

To the httpd.conf and then I added the following to the same file in the directories that I wanted to serve with html.gz files.

```

SetOutputFilter gz-to-html

```

Then you just restart your apache2 server and wala.  It serves up the doc files from the .html.gz.  I also added another type for plain .gz file that converted them to text because alot of the rest of the gz'ed files were text/plain type and had no extra extensions.

----------

## random-feed

Sorry for digging up the ancient thread, but...

This is my problem exactly. I installed apache2 about 4 months ago, and browsing my /doc was not a problem, .gz files were opened in firefox as plain text without additional hacking of apache2.conf. However, I recently upgraded apache as described here. Guess what? The .gz files no longer displayed, firefox suggested to save them on my hard drive instead.

I have been looking at the files in the backup of my conf/ dir, tried applying some changes to httpd.conf, alas. I cannot get this to work, unles I follow Jaminadi's advice above. I know his way will work, but this used to be a generic feature.

Any ideas on this? Are there any modules that I need to load additionaly? What went wrong with .gz-ed text files and httpd?

----------

## tecknojunky

I'd love to do this (groking /usr/share/doc from my broswer), but without having to install Apache on my box.  Since you can open local files with file:///, I was wondering if you could tell the browser (firefox for me) to autouncompress .txt.gz extention.  Can it be done?

----------

## random-feed

well, I need to browse the docs on my other box...

anyway, I found a way to make gzip-ed text to show as text in the browser without external filters. I commented out

```
#AddType application/x-gzip gz tgz

```

and left only:

```
AddEncoding x-gzip gz tgz

```

Thus, the server response became:

  HTTP request sent, awaiting response...

  HTTP/1.1 200 OK

  Date: Thu, 27 Oct 2005 20:41:33 GMT

  Server: Apache

  Last-Modified: Sun, 23 Oct 2005 23:33:12 GMT

  ETag: "e928-82e-5478de00"

  Accept-Ranges: bytes

  Content-Length: 2094

  Keep-Alive: timeout=5, max=100

  Connection: Keep-Alive

  Content-Type: text/plain; charset=ISO-8859-1

  Content-Encoding: x-gzip

Length: 2,094 (2.0K) [text/plain]

This is sure to confuse browsers when serving gzip-ed binary files, but works without external filters.

----------

