views:

2806

answers:

7

I am serving all content through apache with Content-Encoding: zip but that compresses on the fly. A good amount of my content is static files on the disk. I want to gzip the files beforehand rather than compressing them every time they are requested.

This is something that, I believe, mod_gzip did in Apache 1.x automatically, but just having the file with .gz next to it. That's no longer the case with mod_deflate.

+5  A: 

This functionality was misplaced in mod_gzip anyway. In Apache 2.x, you do that with content negotiation. Specifically, you need to enable MultiViews with the Options directive and you need to specify your encoding types with the AddEncoding directive.

Aristotle Pagaltzis
A: 

You can use mod_cache to proxy local content in memory or on disk. I don't know if this will work as expected with mod_deflate.

bmatthews68
+1  A: 

mod_gzip compressed content on the fly as well. You can pre-compress the files by actually logging into your server, and doing it from shell.

cd /var/www/.../data/
for file in *; do
    gzip -c $file > $file.gz;
done;
Aeon
This will remove the original files, which means clients that don't have Aceept-Encoding: gzip won't be serviced.
Otto
good point, updated.
Aeon
While you're editing, why not add -9 and get the highest compression possible. My 1500 files compressed in 38 seconds, so it's worth doing to save every byte possible in bandwidth and download time. :)(Also wishing I could edit my typo in my previous comment. Ugh)
Otto
-9 is the default anyway.
Aristotle Pagaltzis
Not according to the man page on my Mac, it says -6 is the default.
Otto
+3  A: 

To answer my own question with the really simple line I was missing in my confiuration:

Options FollowSymLinks MultiViews

I was missing the MultiViews option. It's there in the Ubuntu default web server configuration, so don't be like me and drop it off.

Also I wrote a quick Rake task to compress all the files.

namespace :static do
    desc "Gzip compress the static content so Apache doesn't need to do it on-the-fly."
    task :compress do
     puts "Gzipping js, html and css files."
     Dir.glob("#{RAILS_ROOT}/public/**/*.{js,html,css}") do |file|
      system "gzip -c -9 #{file} > #{file}.gz"
     end
    end
end
Otto
+1  A: 

I have an Apache 2 built from source, and I found I had to modify the following in my httpd.conf file:

Add MultiViews to Options:

Options Indexes FollowSymLinks MultiViews

Uncomment AddEncoding:

AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz

Comment AddType:

#AddType application/x-compress .Z
#AddType application/x-gzip .gz .tgz
brianegge
A: 

This is mostly working for me. But if I go to http://ismyblogworking.com/www.whatsthatbug.com to check http compression, there is one problem:

"# Your blog page content type is application/x-gzip, not HTML or XHTML."

This is causing a few people to get a download prompt instead of the compressed page. Do I need to use a Content-Type tag or something to fix this?

EDIT: Nevermind, I think I just wasn't patient enough. It appears to be correct now.

Daniel Jacobs
A: 

I have the same issue in my Ubuntu 9.10 with apache. I have enabled mod_defleat but enable to support html.gz pages to server. I also add the Multiviews option in my virtualhost settings but still it ask me to download the file.

any one can help me the exact settings