2

How can I get Apache 2.2 on Centos to serve static .html.gz files from local disk to browsers, without them being prompted to download the file (ie - I want it rendered normally in the browser)?

jamespo
  • 1,698
  • 12
  • 12
  • 1
    Why do you need to do that? You can gunzip them and serve them compressed using apache module `mod_deflate`. – Khaled May 09 '12 at 12:04
  • 2
    See http://stackoverflow.com/questions/75482/how-can-i-pre-compress-files-with-mod-deflate-in-apache-2-x – symcbean May 09 '12 at 13:22
  • I'd like to save local disk space by precompressing and the other question doesn't go into detail - a config snippet would be nice – jamespo May 09 '12 at 18:48

2 Answers2

1

Try this:

LoadModule deflate_module modules/mod_deflate.so
<Directory /path/to/gzipped/files>
   SetOutputFilter INFLATE
</Directory>
Jenny D
  • 27,780
  • 21
  • 75
  • 114
0

Use the following:

# Location block does not work for MultiviewsMatch
<Directory /var/www/html>
  AddEncoding x-gzip .gz
  Options +MultiViews
  MultiviewsMatch Filters
</Directory>

Make sure mod_negotiation, mod_deflate, and mod_mime are loaded elsewhere in the config. They should be standard. On my CentOS install, it appears the AddEncoding line is present but commented out. Just uncommenting that line may be sufficient.

It's a good idea to limit the scope of this setting - as it may result in .gz files being served as content-encoded everywhere, even when you want to send them as a download.

jmanning2k
  • 302
  • 2
  • 9
  • unfortunately I still get prompted to download the .gz – jamespo May 16 '12 at 09:50
  • Comment out 'AddType application/x-gzip .gz .tgz' in httpd.conf, and it will no longer download those files. They are now an encoding, not a type. You can AddType and AddEncoding on a Directory or Location basis to toggle this behavior. – jmanning2k Jun 15 '12 at 15:19