Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running a CentOS server and I want to save bandwidth, make pages faster, all that. How can I turn on http compression? Is it a module I enable for all sites? Can it be that simple?

share|improve this question
Check out gzipwtf.com. Here you can see which files served are compressed while being served by the server. – user23221 Sep 11 '12 at 15:15
up vote 2 down vote accepted

Use mod_deflate.

Add this to your apache config:

LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so
<Location />
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css

Obviously if the path your system uses for apache modules differs then you'll need to use the correct path.

share|improve this answer
For the CentOS 5 httpd rpm, mod_deflate is included and already loaded. You do need to use the DEFLATE output filter as bahamat describes above. – jsbillings Feb 3 '11 at 3:47
I added the LoadModule to a conf in conf.d and yeah, after restarting apache it's already loaded. How can I tell if it's serving everything compressed and why would google keep telling me to compress everything? Guess those are questions best asked elsewhere. – tooshel Feb 3 '11 at 17:08
If you look at the headers (each browser has its own way, or use a sniffer such as wireshark or tcpflow to see them) one of them will be something like Content-Encoding:gzip. You should use an actual desktop browser (e.g., firefox, chrome, etc) rather than a lower level client (lynx, curl, telnet, etc) because the lower level clients may not support/request/advertise compression capability. – bahamat Feb 3 '11 at 17:56
I think the problem is I needed to add AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css to httpd.conf. Now it seems to be working. – tooshel Feb 4 '11 at 16:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.