I’ve been auditing apache web logs from statistics gathered in AWStats. I found 6 different IP addresses that are using a lot of the servers bandwidth. After looking at the logs, I discovered one of the IP addresses was a spammer and the rest are from web robots or bots. One bot used over 2.5GB of traffic last month. That is unbelievable. That is 2.5% of the months bandwidth. Of course Google and Yahoo combined have downloaded almost 30GB, but we want Google and Yahoo to index our sites. So what can we do to save our bandwidth and still provide the information to the search engines? Compress it with Mod_deflate!
The mod_deflate module in Apache is not new. What is new is the trend to use it. The deflate module uses gzip compression and is relatively fast in comparison to the bandwidth time. You can do the math, but if your page was 1MB and took 20 seconds to download, and compressed it is 250k and takes 1 second to compress, 5 second to download, and 2 second to decompress, the compression method is faster. You can crunch numbers till you are blue in the face, but the basic premise holds true.
First, you need to make sure the mod_deflate module is enabled in apache. Look for the line in your apache configuration files and uncomment:
LoadModule deflate_module modules/mod_deflate.so
Then add the following lines within a <Location> or <VirtualHost> section.
SetInputFilter DEFLATE
The above will compress everything. Instead of compressing everything, especially if you have a lot of files on your web site such as images, media, zip files, etc.. that are already compressed, you may want to only add compression for particular content types. To compress specific content types, replace the SetInputFilter with one or more of the following.
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-httpd-php
If you work with other content types such as application/xml, you can add those as well.
You can test your server by using the GID Network gzip test located here: http://www.gidnetwork.com/tools/gzip-test.php
Now that your web server is using compression, you can focus on other things like programming or eating pizza.
One Response
Article about optimize Apache2 by mod_deflate setup
http://railsgeek.com/2008/12/16/apache2-httpd-improve-perfomance-mod_deflate-gzip
Comments are closed.