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?
1 Answer
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
</Location>
Obviously if the path your system uses for apache modules differs then you'll need to use the correct path.
-
1For 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. Feb 3, 2011 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.– tooshelFeb 3, 2011 at 17:08
-
1If 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.– bahamatFeb 3, 2011 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.– tooshelFeb 4, 2011 at 16:27