Thursday, January 21, 2010

Enable Gzip on Apache Http server

Enable Gzip, modify the httpd.conf:

Apache Httpd.conf change:

LoadModule deflate_module modules/mod_deflate.so

LoadModule headers_module modules/mod_headers.so

.....

#Enable Gzip



# we do not need to 9 level, due to CPU% is high but no further compression benefit
DeflateCompressionLevel 7



# Insert filter
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/javascript application/x-javascript

AddOutputFilter DEFLATE css js


# Netscape 4.x has some problems...

BrowserMatch ^Mozilla/4 gzip-only-text/html


# Netscape 4.06-4.08 have some more problems

BrowserMatch ^Mozilla/4\.0[678] no-gzip



# MSIE masquerades as Netscape, but it is fine

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html



# Don't compress images and already compressed files

SetEnvIfNoCase Request_URI \\.(?:gif|jpg|cab|jpe?g|exe|bmp|rar|zip|swf|png)$ no-gzip dont-vary



# Make sure proxies don't deliver the wrong content, need load mod_headers.so

Header append Vary User-Agent env=!dont-vary





or if you want things simple(may bring some bugs on certain browsers):


DeflateCompressionLevel 7
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css

No comments:

Post a Comment