<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Computer Solutions Blog &#187; Mod_Expires</title>
	<atom:link href="http://www.computersolutions.cn/blog/tag/mod_expires/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.computersolutions.cn/blog</link>
	<description>Whats happening at Computer Solutions</description>
	<lastBuildDate>Fri, 13 Jan 2012 02:32:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Speeding up Apache</title>
		<link>http://www.computersolutions.cn/blog/2009/03/speeding-up-apache/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=speeding-up-apache</link>
		<comments>http://www.computersolutions.cn/blog/2009/03/speeding-up-apache/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 06:14:54 +0000</pubDate>
		<dc:creator>Lawrence Sheed</dc:creator>
				<category><![CDATA[Technical Mumbo Jumbo]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Mod_Deflate]]></category>
		<category><![CDATA[Mod_Expires]]></category>
		<category><![CDATA[Tuning]]></category>

		<guid isPermaLink="false">http://www.computersolutions.cn/blog/?p=143</guid>
		<description><![CDATA[When I get time, I go through the logs and check out how the servers are doing. One thing that I haven&#8217;t really done recently is to optimize the way things are configured. The typical solution in most scenario&#8217;s is to throw faster hardware at things (something we do when necessary!), but sometimes a few [...]]]></description>
			<content:encoded><![CDATA[<p>When I get time, I go through the logs and check out how the servers are doing.</p>
<p>One thing that I haven&#8217;t really done recently is to optimize the way things are configured.<br />
The typical solution in most scenario&#8217;s is to throw faster hardware at things (something we do when necessary!), but sometimes a few minutes configuration can help speed things up tremendously.</p>
<p>Below are some tips for optimizing apache a little.</p>
<p><span id="more-143"></span></p>
<p>I&#8217;m going to assume you&#8217;re running apache2.  If not, why not?</p>
<p>First thing to do is to enable 2 modules.  Mod_Deflate and Mod_Expires</p>
<p>a2enmod deflate</p>
<p>a2enmod expires</p>
<p>Mod_Deflate is a nice Apache module that allows us to gzip files  when we send them to the browser.  This helps load times quite nicely &#8211; as network traffic is reduced.</p>
<p>In our systems Apache is over in /etc/apache2/<br />
The module configuration is done in mods-enabled</p>
<p>First up, we&#8217;ll configure Mod_Deflate.</p>
<p>pico /etc/apache2/mods-enabled/deflate.conf</p>
<p style="padding-left: 30px;">&lt;IfModule mod_deflate.c&gt;<br />
AddOutputFilterByType DEFLATE text/plain<br />
AddOutputFilterByType DEFLATE text/html<br />
AddOutputFilterByType DEFLATE text/xml<br />
AddOutputFilterByType DEFLATE text/css<br />
AddOutputFilterByType DEFLATE text/javascript<br />
AddOutputFilterByType DEFLATE application/xml<br />
AddOutputFilterByType DEFLATE application/xhtml+xml<br />
AddOutputFilterByType DEFLATE application/rss+xml<br />
AddOutputFilterByType DEFLATE application/javascript<br />
AddOutputFilterByType DEFLATE application/x-javascript<br />
AddOutputFilterByType DEFLATE application/x-httpd-php<br />
AddOutputFilterByType DEFLATE application/x-httpd-fastphp<br />
AddOutputFilterByType DEFLATE application/x-httpd-eruby<br />
AddOutputFilterByType DEFLATE image/svg+xml</p>
<p>DeflateCompressionLevel 9</p>
<p>BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
BrowserMatch bMSIEs(7|8) !no-gzip !gzip-only-text/html</p>
<p>SetEnvIf User-Agent &#8220;.*MSIE.*&#8221; nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0</p>
<p>&lt;/IfModule&gt;</p>
<p>I&#8217;ll go over what we&#8217;ve done below;</p>
<p>If you examine the file above, you&#8217;ll see that the first thing we do, is to check if mod_deflate is loaded with the IfModule directive.</p>
<p>We then setup compression for various file types -</p>
<p><strong>AddOutputFilterByType DEFLATE  &#8230;.</strong></p>
<p>While we can compress everything, and just exclude certain files, its usually safer to specify whats compressed.</p>
<p>We then set compression to maximum &#8211; computers these days have ample excess CPU, so its not really a concern anymore.</p>
<p><strong>DeflateCompressionLevel 9</strong></p>
<p>The next lines are to specify exceptions to the compression rules.  Ancient versions of Netscape don&#8217;t work so well with compression, so we disable it.  Internet Explorer also has a few issues also, so we setup an appropriate rule.</p>
<p><strong>BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
BrowserMatch bMSIEs(7|8) !no-gzip !gzip-only-text/html</strong></p>
<p>The last line is to force compatibility with older IE versions.  IE is a bit buggy, as we&#8217;ve noted.</p>
<p><strong>BrowserMatch bMSIEs(7|8) !no-gzip !gzip-only-text/html</strong></p>
<p>We&#8217;ll now check to see that we haven&#8217;t made any mistakes, and Apache2 runs ok.</p>
<p>apache2ctl configtest</p>
<p>If you see any errors, fix and retest.</p>
<p>Restart apache2</p>
<p>apache2ctl restart</p>
<p>Load up FireFox.  You&#8217;ll need to have some plugins installed to test.<br />
Go get FireBug, and YSlow, install and come back.</p>
<p>Done?</p>
<p>Ok, now open a page from the site, and click YSlow.</p>
<p>You should see now that the css, js, and php files are compressed with GZip.</p>
<p>Our next step is to setup Mod_Expires</p>
<p>pico /etc/apache2/mods-enabled/expires.conf</p>
<p style="padding-left: 30px;">&lt;IfModule mod_expires.c&gt;<br />
ExpiresActive On<br />
ExpiresByType image/gif A21600<br />
ExpiresByType image/jpeg A21600<br />
ExpiresByType text/css A21600<br />
ExpiresByType application/x-javascript A21600<br />
&lt;/IfModule&gt;</p>
<p>Essentially, what we&#8217;re doing above is turning on Content Expiry.  Content Expiry is the time that a browser will cache a file for before it reloads it.  For your average site things like images, javascript and css don&#8217;t change that much, so we can tell the browser to explicitly cache them.</p>
<p>The number next to the Expiry is the time that the file is valid for in seconds.<br />
(after that point, the browser should reload the file from the server).</p>
<p>In our setup above, we&#8217;ve set that images and css and javascript files should be kept for 6 hours.<br />
A21600 means &#8211; after 6hrs (60seconds x 60minutes x 6 = 21600)</p>
<p>I&#8217;d suggest using a low, but similar time span to avoid caching issues.  This would mostly affect website developers, rather than end users though, as they&#8217;re more likely to upload and change files frequently during testing.</p>
<p>Restart apache, and check again in YSlow / Firebug to see that the images and CSS are being cached.  If they are, congratulations, you&#8217;re done.</p>
<p>You should see a nice improvement on site load times, and things should feel snappier to end users.<br />
It will also reduce your server load, which is a nice benefit!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.computersolutions.cn/blog/2009/03/speeding-up-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

