<?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>UNIXy &#187; patch</title>
	<atom:link href="http://blog.unixy.net/tag/patch/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.unixy.net</link>
	<description>Fully Managed Dedicated Servers</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:37:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PHP built-in Web server for development</title>
		<link>http://blog.unixy.net/2011/03/php-built-in-web-server-for-development/</link>
		<comments>http://blog.unixy.net/2011/03/php-built-in-web-server-for-development/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 04:32:19 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Future]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[built-in]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[start]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=1234</guid>
		<description><![CDATA[A PHP built-in Web server has been proposed as a Request For Comment (RFC), which includes a patch to the PHP source code base. ]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2011%2F03%2Fphp-built-in-web-server-for-development%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2011%2F03%2Fphp-built-in-web-server-for-development%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>A <a href="http://wiki.php.net/rfc/builtinwebserver">PHP built-in Web server</a> has been proposed as a Request For Comment (RFC), which includes a patch to the PHP source code base. If the PHP maintainers decide to move forward with the proposal, we&#8217;d soon see an embedded Web server shipping with PHP CLI. Here&#8217;s how one would start and run the Web server:</p>
<blockquote><p>php -S localhost:8000<br />
Server is listening on localhost:8000&#8230; Press CTRL-C to quit.<br />
[Thu Mar  3 05:42:06 2011] ::1:56258: /<br />
[Thu Mar  3 05:42:06 2011] ::1:56259: /?=PHPE9568F34-D428-11d2-A769-00AA001ACF42<br />
[Thu Mar  3 05:42:06 2011] ::1:56260: /?=PHPE9568F35-D428-11d2-A769-00AA001ACF42</p></blockquote>
<p>In a way, it&#8217;s similar to how one would start the Django or web.py development server. Interesting patch&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2011/03/php-built-in-web-server-for-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to build your own CDN using BIND, GeoIP, Nginx, and Varnish</title>
		<link>http://blog.unixy.net/2010/07/how-to-build-your-own-cdn-using-bind-geoip-nginx-and-varnish/</link>
		<comments>http://blog.unixy.net/2010/07/how-to-build-your-own-cdn-using-bind-geoip-nginx-and-varnish/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 18:40:51 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Challenge]]></category>
		<category><![CDATA[akamai]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[build own cdn]]></category>
		<category><![CDATA[build your own cdn]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[CDN]]></category>
		<category><![CDATA[geodns]]></category>
		<category><![CDATA[GeoIP]]></category>
		<category><![CDATA[global CDN]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[own CDN]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[private CDN]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=342</guid>
		<description><![CDATA[In this article, we shall outline the steps required to build a private Content Delivery or Distribution Network (CDN) using Varnish Cache, Nginx, BIND, and GeoIP. The goal is to build a CDN using free, readily available software but most importantly spend the least amount of funds possible. ]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F07%2Fhow-to-build-your-own-cdn-using-bind-geoip-nginx-and-varnish%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F07%2Fhow-to-build-your-own-cdn-using-bind-geoip-nginx-and-varnish%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>Update (2011-Sep-14)</strong>: UNIXy has built CDN software that you can run on your own hardware (or virtual machine) to build your own secure, flexible, private CDN. We&#8217;re working with individuals and organizations that are willing to trial the software. If you&#8217;re interested in joining the beta program for the CDN software, don&#8217;t hesitate to contact us. UNIXY clients are also welcome to join this program. Moreover they&#8217;ll benefit from our fully managed service and continued engineering assistance with the software. Do contact us today to get the ball rolling:<a title="CDN Consulting" href="https://www.unixy.net/secure/contact.php" target="_self">https://www.unixy.net/secure/contact.php</a></p>
<p><strong>Update (2011-Jul-07):</strong> <a title="Fastlayer" href="http://fastlayer.com" target="_blank">Fastlayer</a>, <a title="Varnish" href="http://www.unixy.net/varnish" target="_blank">Varnish</a> for the <a title="Fastlayer" href="http://fastlayer.com" target="_blank">cloud</a>, is born. Fastlayer is a multi-tenant accelerator software appliance built to run on as small as a virtual machine. Read more here: <a title="Fastlayer.com" href="http://fastlayer.com" target="_blank">fastlayer.com</a></p>
<p><strong>Update (2011-Feb-22)</strong>: We&#8217;ve released a Varnish based cPanel script should you be interested in boosting server performance. The benchmarks (conducted &amp; confirmed by third parties) have proved that Varnish+Apache is much faster than Nginx, Litespeed, &amp; Lighttpd. Read more here: <a title="Varnish cPanel" href="http://www.unixy.net/varnish" target="_self">http://www.unixy.net/varnish</a></p>
<p>In this article, we shall outline the steps required to build a private Content Delivery or Distribution Network (CDN) using a <a title="VPS" href="http://www.unixy.net/vps-hosting" target="_self">VPS</a> with <a title="Varnish Cache" href="http://www.varnish-cache.org" target="_blank">Varnish</a> Cache and <a title="Nginx" href="http://www.nginx.org" target="_blank">Nginx</a>. The goal is to build a CDN using free, readily available software but most importantly spend the least amount of funds possible. To this end, all nodes participating in this network are going to be virtual machines (Xen, Virtuozzo, OpenVZ, etc). Should you have any questions or comments on the configuration of this CDN, please post them in this forum: <a title="Varnish Cache Forum" href="http://www.varnish-cache.info/" target="_blank">http://www.varnish-cache.info/</a></p>
<p>Our global CDN can not only keep the latest copy of static files closer to our global visitors but can also cache the most used pages (dynamic or not) in memory on the edge nodes! This means less trips to the geographically distant and slower Dynamic Node (see below). This is similar to what <a title="Akamai" href="http://www.akamai.com" target="_blank">Akamai</a> and other well known firms do, only at a fraction of the cost. However, in this article, and to keep things simple, we will only be caching static files.</p>
<p>Some of you might be surprised to learn that we built this global CDN free of charge for one of our beloved customers. UNIXY offers truly fully managed dedicated servers and clusters with <strong><a title="Managed server" href="http://www.unixy.net/dedicated-servers" target="_self">managed servers</a></strong><strong> starting as low as $45</strong>. Our motto is simple: what you cannot do with a few mouse clicks, we will gladly do it for you! Please visit us online when you have a chance: <a title="Truly Fully Managed Dedicated Servers" href="http://www.unixy.net" target="_self">http://www.unixy.net</a>. Please do ask if you have any question or comment. No question is minor!</p>
<ul>
<li><strong>The Big Picture</strong></li>
</ul>
<p>The illustration below presents a logical layout of our CDN. Edge nodes can be located just about anywhere in the world. One could also add more nodes at any location should there be a capacity need. The Dynamic Content Node will typically run a mixture of MySQL, Apache, and server-side software built using PHP, Ruby, Python, .Net, or any language for that matter.</p>
<p>&nbsp;</p>
<div id="attachment_344" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.unixy.net/wp-content/uploads/2010/07/CDN_design.png"><img class="size-medium wp-image-344" title="Global CDN Logical Design" src="http://blog.unixy.net/wp-content/uploads/2010/07/CDN_design-300x273.png" alt="Global CDN" width="300" height="273" /></a><p class="wp-caption-text">Global CDN</p></div>
<p>&nbsp;</p>
<ul>
<li>Role of Each Software Component</li>
</ul>
<p>Nginx is a lightweight high-performance Web server that is able to handle large traffic consistently. We are leveraging its proxy and caching capabilities. We shall compile Nginx and leverage the proxy module. This module allows us to cache data on the local disks of the remote edge locations.</p>
<p>As its name implies, Varnish Cache is a high-performance caching engine used to keep recently accessed content in memory for fastest access. Varnish is not a Web server. Hence our need to bundle it with Nginx, which is acting as a Web server at the edge nodes. We will cover Varnish in detail in our next installment.</p>
<p>And finally the glue that holds all of these components together: BIND. BIND is the DNS software used to map Internet host names to IP addresses. We shall patch Bind to add geographical filters support. In other words, BIND will serve each client the IP of closest edge node in the CDN. For example, an vistor from Africa will receive the edge node IP of South Africa or Morocco depending on the filters. We will touch on this later.</p>
<ul>
<li>Node Layout</li>
</ul>
<p>At a minimum, we will need two nodes to demo and build our private CDN. That&#8217;s one Dynamic Content Node and one Edge Location node. The Dynamic Content Node will run the full LAMP stack along with BIND and the geographical filters patch. The Edge Location node will run Nginx and Varnish. One could always run BIND+GeoIP on a separate node as it is good practice. We will assign the hostname dynamic_content to the Dynamic Content Node and edge_node to the Edge Location.</p>
<ul>
<li>Installation and configuration</li>
</ul>
<p>Download BIND from ISC: <a href="http://www.bind9.net/download">http://www.bind9.net/download</a></p>
<p>Download MaxMind&#8217;s C API: <a href="http://geolite.maxmind.com/download/geoip/api/c/">http://geolite.maxmind.com/download/geoip/api/c/</a></p>
<blockquote>
<div id="_mcePaste">[root@dynamic_node /]# cd /usr/src/</div>
<div id="_mcePaste">[root@dynamic_node src]# wget http://mirrors.24-7-solutions.net/pub/isc/bind9/9.2.4/bind-9.2.4.tar.gz</div>
<div>[root@dynamic_node src]# wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz</div>
<div>[root@dynamic_node src]# tar -xzvf bind-9.2.4.tar.gz</div>
<div>[root@dynamic_node src]# tar -xzvf GeoIP-1.4.6.tar.gz</div>
<div>[root@dynamic_node src]# cd GeoIP-1.4.6</div>
<div>[root@dynamic_node GeoIP-1.4.6]# ./configure &#8211;prefix=/usr/local/geoip</div>
<div>[root@dynamic_node GeoIP-1.4.6]# make</div>
<div>[root@dynamic_node GeoIP-1.4.6]# make install</div>
<div>[root@dynamic_node GeoIP-1.4.6]# cd ..</div>
<div>
<div>[root@dynamic_node src]# patch -p0 &lt; bind-9.2.4-geodns-patch/patch.diff</div>
<div>[root@dynamic_node src]# cd bind-9.2.4</div>
<div>[root@dynamic_node bind-9.2.4]# CFLAGS=&#8221;-I/usr/local/geoip/include&#8221; LDFLAGS=&#8221;-L/usr/local/geoip/lib -lGeoIP&#8221; ./configure &#8211;prefix=/usr/local/bind</div>
<div>[root@dynamic_node bind-9.2.4]# make</div>
<div>[root@dynamic_node bind-9.2.4]# make install</div>
</div>
</blockquote>
<div>Bind-GeoIP comes with a named.conf file with examples on how to use filtering. Setup your zone files and test them accordingly. The GeoIP patch official page has instructions and examples. Be sure to read over it should you need help: <a href="http://www.caraytech.com/geodns/">http://www.caraytech.com/geodns/</a>. If you do not have access to nodes in the different geo locations around the world to test your BIND configuration, http://traceroute.org is a good resource to leverage. It allows one to test DNS resolution using a looking glass (ping).</div>
<div>Here is how the filters should look inside named.conf:</div>
<div>
<blockquote>
<div>view &#8220;us&#8221; {</div>
<div>// Match clients from US &amp; Canada</div>
<div>match-clients { country_US; country_CA; };</div>
<div>// Provide recursive service to internal clients only.</div>
<div>recursion no;</div>
<div>zone &#8220;cdn.unixy.net&#8221; {</div>
<div>type master;</div>
<div>file &#8220;pri/unixy-us.db&#8221;;</div>
<div>};</div>
<div>zone &#8220;.&#8221; IN {</div>
<div>type hint;</div>
<div>file &#8220;named.ca&#8221;;</div>
<div>};</div>
<div>};</div>
<div>view &#8220;latin&#8221; {</div>
<div>// Match from Argentina, Chile and Brazil</div>
<div>match-clients { country_AR; country_CL; country_BR; };</div>
<div>// Provide recursive service to internal clients only.</div>
<div>recursion no;</div>
<div>zone &#8220;cdn.unixy.net&#8221; {</div>
<div>type master;</div>
<div>file &#8220;pri/unixy-latin.db&#8221;;</div>
<div>};</div>
<div>zone &#8220;.&#8221; IN {</div>
<div>type hint;</div>
<div>file &#8220;named.ca&#8221;;</div>
<div>};</div>
<div>};</div>
</blockquote>
</div>
<div>Let us move on now and install Nginx and Varnish.</div>
<blockquote>
<div>[root@edge_node src]# wget http://nginx.org/download/nginx-0.8.45.tar.gz</div>
<div>[root@edge_node src]# tar -xzvf nginx-0.8.45.tar.gz</div>
<div>[root@edge_node src]# cd nginx-0.8.45</div>
<div>[root@edge_node nginx-0.8.45]# ./configure &#8211;prefix=/usr/local/nginx &#8211;with-http_realip_module</div>
<div>[root@edge_node nginx-0.8.45]# make</div>
<div>[root@edge_node nginx-0.8.45]# make install</div>
</blockquote>
<div>Here is our nginx.conf file with relevant lines only. All other configuration options are stock Nginx:</div>
<p>&nbsp;</p>
<blockquote>
<div>http {</div>
<div>include       mime.types;</div>
<div>default_type  application/octet-stream;</div>
<div>sendfile        on;</div>
<div>keepalive_timeout  65;</div>
<div>upstream dynamic_node {</div>
<div style="padding-left: 30px;">server 1.1.1.1:80; # 1.1.1.1 is the IP of the Dynamic Node</div>
<div>}</div>
<div>server {</div>
<div>listen       81;</div>
<div>server_name  cdn.unixy.net;</div>
<div>location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|htm|html|js|css|mp3|swf|ico|flv)$ {</div>
<div>proxy_set_header  X-Real-IP  $remote_addr;</div>
<div><strong>proxy_pass http://dynamic_node;</strong></div>
<div><strong>proxy_store /var/www/cache$uri;</strong></div>
<div><strong>proxy_store_access user:rw group:rw all:r;</strong></div>
<div>}</div>
</blockquote>
<div>In bold above are configuration lines that are key and define our private CDN. The upstream is essentially going to be our Dynamic Node to which we pass requests that cannot be served from cache. Also, Nginx will only be caching static files like GIF, PNG, and JS. Varnish on the other hand will be caching dynamic pages. Notice how Nginx listens on port 81. This is because Varnish will listen on port 80 and will forward requests to Nginx on port 80. More on Varnish later.</div>
<div>Notice how we are using cdn.unixy.net as the handle for our virtual host name. It can be just about anything depending on your configuration. Once the cache builds up, you should start seeing files and directories being populated under /var/www/ as instructed above.</div>
<div>
<p>A few seconds of browsing and the disk cache is already populating:</p>
</div>
<div>
<blockquote><p>[root@edge_node /]# ls -al /var/www/cache<br />
contact-unixy css images index.html javascript js<br />
[root@edge_node /]#</p></blockquote>
</div>
<div>Next we will proceed with installing Varnish. Varnish will act an in-memory cache. While it is not necessary, it can improve response time greatly. Nonetheless, installing Varnish does add a level of complexity to our configuration.</div>
<blockquote>
<div>[root@edge_node src]# wget http://downloads.sourceforge.net/project/varnish/varnish/2.1.2/varnish-2.1.2.tar.gz?use_mirror=cdnetworks-us-1&amp;ts=1279434397</div>
<div>[root@edge_node src]# tar -xzvf varnish-2.1.2.tar.gz</div>
<div>[root@edge_node src]# tar -xzvf varnish-2.1.2.tar.gz</div>
<div>[root@edge_node varnish-2.1.2]# ./configure &#8211;prefix=/usr/local/varnish</div>
<div>[root@edge_node varnish-2.1.2]# make</div>
<div>[root@edge_node varnish-2.1.2]# make install</div>
</blockquote>
<div>Be sure to follow guides online on the initial setup of Varnish. This article only covers the configuration of the CDN. There are certainly additional Varnish options that need tuning but those are most likely peculiar to your application.</div>
<div>
<blockquote>
<div>backend default {</div>
<div style="padding-left: 30px;">.host = &#8220;127.0.0.1&#8243;;</div>
<div style="padding-left: 30px;">.port = &#8220;81&#8243;;</div>
<div>}</div>
</blockquote>
</div>
<div>
<blockquote>
<div>sub vcl_recv {</div>
<div style="padding-left: 30px;">.<br />
.<br />
.<br />
if (req.url ~ &#8220;\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$&#8221;) {</div>
<div style="padding-left: 60px;">return (lookup);</div>
<div style="padding-left: 30px;">}<br />
.<br />
.<br />
.</div>
<div>}</div>
</blockquote>
<blockquote>
<div>sub vcl_fetch {</div>
<div style="padding-left: 30px;">.<br />
.<br />
.<br />
if (req.url ~ &#8220;\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$&#8221;) {</div>
<div style="padding-left: 60px;">unset obj.http.set-cookie;</div>
<div style="padding-left: 30px;">}<br />
.<br />
.<br />
.</div>
<div>}</div>
</blockquote>
<div>Go ahead and startup Varnish and browse around you portal a bit to build the cache. Monitor the command varnishstat on the edge node and you will be able to see the cache hits and misses. There should be more hits as the cache builds up over time and more objects are accessed.</div>
</div>
<div>
<p>&nbsp;</p>
<ul>
<li>Wrap up</li>
</ul>
<p><strong> </strong><strong><span style="font-weight: normal;">The instructions above can replicated across however many additional Edge Nodes you want to add. One could also add redundancy to the BIND+GeoIP setup by configuring secondary nodes. The illustration below shows the flow of a request from top to bottom.</span><br />
</strong></p>
<div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="attachment_389" class="wp-caption aligncenter" style="width: 437px"><a href="http://blog.unixy.net/wp-content/uploads/2010/07/text3648.png"><img class="size-medium wp-image-389 " title="CDN Request and Response Flow" src="http://blog.unixy.net/wp-content/uploads/2010/07/text3648-300x237.png" alt="CDN Built Using Nginx and Varnish" width="427" height="338" /></a><p class="wp-caption-text">CDN Request and Response Flow</p></div>
<p><strong> </strong>That&#8217;s all folks! I hope you enjoyed this article.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2010/07/how-to-build-your-own-cdn-using-bind-geoip-nginx-and-varnish/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

