kieranbarnes these are the things i learnt today

Enabling mod_deflate/gzip globally on cPanel

Posted on January 26, 2010

There's far too many reasons to mention why you should enable mod_deflate to gzip your content served by Apache. Simply put, it makes it go fast.

You can enable mod_deflate in cPanel really easily with /scripts/easyapache. Easy.

Once built, you need to tell it to do something. You'll see a new icon on your sites cPanel now, called "Optimize Site". You can enable it on a per site basis.

Thats all very well, but most users won't know that feature and they will annoy you saying their site isn't very fast.

Lets enable it globally to save any hassle.

You will need to edit your Post VirtualHost Include. In WHM;

  • Apache Configuration
  • Include Editor
  • Select All Versions of Post VirtualHost Include
  • Paste the following below
<IfModule mod_deflate.c>
	AddOutputFilterByType  DEFLATE text/html text/plain text/xml
 
	<IfModule mod_setenvif.c>
		# 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
 
		# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
		# the above regex won’t work. You can use the following
		# workaround to get the desired effect:
		BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
 
		# Don’t compress images
		SetEnvIfNoCase Request_URI \
    		\.(?:exe|t?gz|zip|bz2|sit|rar)$ \
		    no-gzip dont-vary
		SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
 
	</IfModule>
 
	<IfModule mod_headers.c>
		# Make sure proxies don’t deliver the wrong content
		Header append Vary User-Agent env=!dont-vary
	</IfModule>
</IfModule>

Restart apache and enjoy.

You can use tools such as YSlow or Google Page Speed to diagnose your gzip savings.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. Apache2 mod_deflate
    The mod_deflate module provides the DEFLATE output filter that allows output from your server to...
  2. mod_geoip Revisted including stopping spam in phpBB 2
    I've recently moved a client's forum onto a new cPanel server, previously it was on...
  3. Installing mod_evasive on cPanel and/or Apache
    This guide details how to install mod_evasive on cPanel to help protect against DDOS attacks,...
  4. Anonymous apache & PHP for cPanel
    So I've started playing with cPanel/WHM recently. I've got to say it does make my...
  5. Installing memcached on CentOS (cPanel)
    Welcome to hell. No really, compared to installing memcached on Ubuntu, CentOSs really sucks. CentOS...

What this article useful to you?



Let me know, buy me a beer!
Alternatively, if you're feeling impecunious, you may like to subscribe to my RSS feed, or see other articles in the Linux, cPanel/WHM category.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.