<?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>Christoph Blecker &#187; Server Administration</title>
	<atom:link href="http://www.toph.ca/category/technology/server-administration/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.toph.ca</link>
	<description>Growing up in the Internet Age</description>
	<lastBuildDate>Sat, 20 Feb 2010 09:57:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>mod_rewrite and caching servers</title>
		<link>http://www.toph.ca/2008/07/07/mod_rewrite-and-caching-servers/</link>
		<comments>http://www.toph.ca/2008/07/07/mod_rewrite-and-caching-servers/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 09:32:15 +0000</pubDate>
		<dc:creator>Toph</dc:creator>
				<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache configuration]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[image redirection]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[peer1]]></category>
		<category><![CDATA[rapidedge]]></category>

		<guid isPermaLink="false">http://www.toph.ca/?p=28</guid>
		<description><![CDATA[To better learn about the different PEER1 products that I support, I&#8217;ve recently been playing around with the PEER1 Content Delivery Network. The most common CDN set up is to point it at the same webserver you run your main site off of, and then you link back any images or static content back to [...]]]></description>
			<content:encoded><![CDATA[<p>To better learn about the different PEER1 products that I support, I&#8217;ve recently been playing around with the <a href="http://www.rapidedgecdn.com/">PEER1 Content Delivery Network</a>. The most common CDN set up is to point it at the same webserver you run your main site off of, and then you link back any images or static content back to the caching name instead of the primary name. For example, if your site was www.example.com and your CDN was set up at cache1.example.com, you would point both domains at the same server and then link all your images through the cache1.example.com, while all your text pages and such would pull straight from your webserver. Now, while you would also be able to pull everything including the webpages through the cachers, the issue arises with freshness of the page. This holds especially true when you&#8217;re working with dynamic PHP content.</p>
<p>I ended up running into a bit of an issue. I wanted to maximize the amount of content I&#8217;m serving through the CDN, however my website is based off of <a href="http://www.wordpress.org/">WordPress</a>. I had two options.. I could rewrite the entire style I&#8217;m using to staticly grab the files from the caching server, as opposed to the regular webserver, or I could find a way to dynamically redirect all images to come from the caching server as opposed to the regular webserver. I ended up finding a way to do through the Apache <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">mod_rewrite</a> module.</p>
<p>First, I went into the config file for my main toph.ca server and stuck in this line of code:<code><font size=1><br />
&lt;IfModule mod_rewrite.c&gt;<br />
&nbsp;&nbsp;RewriteEngine On<br />
&nbsp;&nbsp;RewriteRule ^(.*)(jpeg|jpg|gif|bmp|png|mp3)$ http://cache.toph.ca$0 [NC,L]<br />
&lt;/IfModule&gt;<br />
</font></code></p>
<p>Then I hopped over and into the config for the caching server (they are running on the same IP using Name-based VirtualHosts) and stuck this in: <code><font size=1><br />
&lt;files ~ "^(.*)(htm|html|php|js|HTM|HTML|PHP|JS)$"&gt;<br />
&nbsp;&nbsp;Order allow,deny<br />
&nbsp;&nbsp;Deny from all<br />
&nbsp;&nbsp;Satisfy All<br />
&lt;/files&gt;<br />
</font></code></p>
<p>Now this does two things. First off, this causes all requests to www.toph.ca for media files to be automatically be redirected to cache.toph.ca. It&#8217;s a simple catch all, and it works! This doesn&#8217;t entirely reduce the load on the server as the requests still have to hit my Apache server to get the redirect, but my server doesn&#8217;t actually have to serve the files unless the cacher doesn&#8217;t have them. The second snippet of code on the cacher prevents the server from serving the actual data html or php files off the server. I don&#8217;t want that caching server serving web pages to users, or getting them indexed in Google.</p>
<p>So there you have it. A quick and dirty way to force all your media content over to a CDN caching service (or any alternative webserver for that matter), and to prevent that server from serving your actual page files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.toph.ca/2008/07/07/mod_rewrite-and-caching-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
