<?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>Vvvegard! &#187; Debian</title>
	<atom:link href="http://www.vvvegard.net/blog/category/debian/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vvvegard.net/blog</link>
	<description>Learn me a book!</description>
	<lastBuildDate>Sun, 27 Feb 2011 03:11:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SSH: Tips and tricks</title>
		<link>http://www.vvvegard.net/blog/ssh-tips-and-tricks/328/</link>
		<comments>http://www.vvvegard.net/blog/ssh-tips-and-tricks/328/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 02:18:32 +0000</pubDate>
		<dc:creator>Vegard Hansen</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[how-to]]></category>

		<guid isPermaLink="false">http://www.vvvegard.net/blog/?p=328</guid>
		<description><![CDATA[I&#8217;ve played around with SSH to some extent, and thought I&#8217;d write down a few nifty features that I like. Kind of a little follow-up on my Key-based authentication and Accessing ArcHTTP-post. Keep in mind that you have to change things like host and user to fit your appropriate needs. scp foo user@host:~/bar # To [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve played around with SSH to some extent, and thought I&#8217;d write down a few nifty features that I like. Kind of a little follow-up on my <a href="http://www.vvvegard.net/blog/key-basert-autentisering-i-linuxbsdosx/54/">Key-based authentication</a> and <a href="http://www.vvvegard.net/blog/accessing-archttp/249/">Accessing ArcHTTP</a>-post. Keep in mind that you have to change things like host and user to fit your appropriate needs.</p>
<pre class="brush: plain; title: Copying files using SCP, placing the file foo your home folder (~/) and naming it bar.;">scp foo user@host:~/bar
# To copy a folder use the prefix -R foo/, like this
scp -R foo/ user@host:~/
</pre>
<pre class="brush: plain; title: Setting up a Socket 5 tunnel and bind it locally to port 8080. Nice feature if you&#039;re on a unsecured network and just too lazy to setup VPN.;">ssh -l user host -D 8080</pre>
<pre class="brush: plain; title: Binding a local port to an external port, an even better way at solving my Accessing ArcHTTP-post. We&#039;re binding the local port 8080 to the remote port 80.;">ssh -l user host -L 8080:localhost:80</pre>
<pre class="brush: plain; title: Configuring a local ssh_config for easy integration with multiple keys, long hostnames and different users. You can override everything using normal prefixes. File is located in ~/.ssh/config, you might need to create it first. For more possible options, check ssh_config(1) in man. To connect to a defined host, just issue ssh foo. &lt;br /&gt;&lt;br /&gt;A configuration can look something like this:;">Host foo
        User root
        HostName host
        IdentityFile ~/.ssh/otherkey
        Compression yes
        CompressionLevel 9
        KeepAlive Yes
Host bar
        User foo
        HostName host
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.vvvegard.net/blog/ssh-tips-and-tricks/328/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache2 wildcard DNS and dynamic virtual hosts</title>
		<link>http://www.vvvegard.net/blog/apache2-wildcard-dns-and-dynamic-virtual-hosts/283/</link>
		<comments>http://www.vvvegard.net/blog/apache2-wildcard-dns-and-dynamic-virtual-hosts/283/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 01:36:53 +0000</pubDate>
		<dc:creator>Vegard Hansen</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Lenny]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[ninja]]></category>
		<category><![CDATA[vhost]]></category>

		<guid isPermaLink="false">http://www.vvvegard.net/blog/?p=283</guid>
		<description><![CDATA[We can utilize the power (.. or lack?) of mod_rewrite in Apache2 to dynamically add subdomains for all subdirectories in a certain folder. I cannot recall where i first read how to do this, but all creds goes to someone on the Internet! Also, this only works &#8220;out-of-the-box&#8221; for Debian Lenny running latest stable version [...]]]></description>
			<content:encoded><![CDATA[<p>We can utilize the power (.. or lack?) of mod_rewrite in Apache2 to dynamically add subdomains for all subdirectories in a certain folder. I cannot recall where i first read how to do this, but all creds goes to someone on the Internet! Also, this only works &#8220;out-of-the-box&#8221; for Debian Lenny running latest stable version of Apache2, but it should work on all systems running Apache2, with slight modification.</p>
<p>First we need to enable some modules:</p>
<pre class="brush: plain; title: Code example:;">
a2enmod rewrite vhost_alias
/etc/init.d/apache2 restart</pre>
<p>Next up we do some rewrite magic, you need to change some paths and domains to reflect your setup, personally I just use some search and replace in nano to reflect whatever domain and site I&#8217;m setting up.</p>
<pre class="brush: plain; title: Code example:;">
&lt;VirtualHost *:80&gt;
ServerName eksempel.no
ServerAlias *.eksempel.no #wildcard catch all
VirtualDocumentRoot /var/www/%1
UseCanonicalName Off
IndexOptions FancyIndexing
### Use mod_rewrite to direct eksempel.no to www.eksempel.no
RewriteEngine On
RewriteCond %{HTTP_HOST} ^eksempel.no
RewriteRule (.*) http://www.%{HTTP_HOST}$1 [R=301,L]
### Logging
LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %&gt;s %b \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;&quot; combined
CustomLog /var/log/apache2/access_log_eksempel combined
&lt;Directory /var/www&gt;
AllowOverride None
&lt;/Directory&gt;
&lt;/VirtualHost&gt;
</pre>
<p>You must also restart Apache2 for your changes to apply.</p>
<pre class="brush: plain; title: Code example:;">
/etc/init.d/apache2 restart
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.vvvegard.net/blog/apache2-wildcard-dns-and-dynamic-virtual-hosts/283/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using rdiff-backup to keep your files safe and secure!</title>
		<link>http://www.vvvegard.net/blog/using-rdiff-backup-to-keep-your-files-safe-and-secure/237/</link>
		<comments>http://www.vvvegard.net/blog/using-rdiff-backup-to-keep-your-files-safe-and-secure/237/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 23:21:25 +0000</pubDate>
		<dc:creator>Vegard Hansen</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Lenny]]></category>

		<guid isPermaLink="false">http://www.vvvegard.net/blog/?p=237</guid>
		<description><![CDATA[Rdiff-backup is a small nifty python-based incremental backup software. Rdiff is similar to rsync, but adds support for incremental and revision-based backup. This way you can keep, in this example, up to 14 days of changes. Rdiff-backup also differs (!) from rsnapshot as it only stores the changes over time of a certain file, and [...]]]></description>
			<content:encoded><![CDATA[<p>Rdiff-backup is a small nifty python-based incremental backup software. Rdiff is similar to rsync, but adds support for incremental and revision-based backup. This way you can keep, in this example, up to 14 days of changes. Rdiff-backup also differs (!) from rsnapshot as it only stores the changes over time of a certain file, and this saves you a lot of storage. It&#8217;s extremely usable for database-backups, as they tend to change little but grow huge.</p>
<p>You might have to do small adjustments to stuff like users and parent directory. In this guide i use /root/ as parent directory for most actions, and all commands should work then.</p>
<p><span id="more-237"></span></p>
<p><strong>Upgrading and Installing</strong></p>
<p>It&#8217;s important that you do this on your target server and the server you are backuping, or else rdiff-backup will not be able to use ssh as it starts an rdiff-server on your target machine.</p>
<p style="padding-left: 30px;">apt-get update<br />
apt-get install rdiff-backup</p>
<p><strong>Setting up SSH with keys</strong></p>
<p>After installing rdiff we need to generate ssh-keys so that you can have automated rdiff-backups. I&#8217;ll only cover this briefly, but if you are unsure try to consult another guide i made about setting up key-based ssh authentication.</p>
<p style="padding-left: 30px;">ssh-keygen<br />
scp .ssh/id_rsa user@host:.ssh/id_rsa</p>
<p>This generates the keys you need and send them to the appropriate user on your remote machine for storing backups. If you are setting up more servers to use the same backup location copy id_rsa.pub over to them.</p>
<p><strong>Using rdiff-backup</strong></p>
<p style="padding-left: 30px;">rdiff-backup -v5 &#8211;print-statistics /local-dir user@host::/remote-dir<br />
rdiff-backup &#8211;remove-older-than 2W user@host::/remote-dir</p>
<p>Now we have created the first and initial backup, this might take some time, depending on your connection speed, disks and CPU. You should be able to watch what&#8217;s stores since we issued the -v5 comand (verbos 5).</p>
<p><strong>Automating it</strong></p>
<p style="padding-left: 30px;">echo &#8220;#!/bin/sh&#8221; &gt;&gt; rdiff-backup.sh<br />
echo &#8220;rdiff-backup -v5 &#8211;print-statistics /local-dir user@host::/remote-dir&#8221; &gt;&gt; rdiff-backup.sh<br />
echo &#8220;rdiff-backup &#8211;remove-older-than 2W user@host::/remote-dir&#8221; &gt;&gt; rdiff-backup.sh</p>
<p><strong>Running it</strong></p>
<p style="padding-left: 30px;">crontab -e</p>
<p>And insert the following line</p>
<p style="padding-left: 30px;">* 0 * * * /root/rdiff-backup.sh</p>
<p>Save it! Now you can just sit back and relax and let &#8216;em backups flow, each night at twelve o&#8217; clock.</p>
<p><strong>Restoring</strong></p>
<p>Maybe the most boring part but also the most important part, restoring. When you restore with rdiff-backup you can restore to any date you want, as long as it&#8217;s still being kept. In this guide we used 2W, or two weeks, so we should be able to restore a file 14 days back. Nifty!</p>
<p style="padding-left: 30px;">rdiff-backup -r 14D user@host::/remote-dir/file /local-dir/file</p>
<p>This will restore the 14 days old file (-r 14D) of &#8220;file&#8221; to &#8220;/local-dir/file&#8221;. Pretty nifty, ey? If you are doing disaster recovery you can also recover an entire directory.</p>
<p><strong>Final words</strong></p>
<p>Do some simple tests, like backing up and restoring. This way you don&#8217;t get caught with your pants down when you actually need to restore something, and you ensure that backups actually are working &#8211; as this guide is not fully tested nor foolproof.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vvvegard.net/blog/using-rdiff-backup-to-keep-your-files-safe-and-secure/237/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmarking opcode php-cachers with Apache2 on Debian Lenny</title>
		<link>http://www.vvvegard.net/blog/benchmarking-opcode-php-cachers-with-apache2-on-debian-lenny/181/</link>
		<comments>http://www.vvvegard.net/blog/benchmarking-opcode-php-cachers-with-apache2-on-debian-lenny/181/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 04:20:35 +0000</pubDate>
		<dc:creator>Vegard Hansen</dc:creator>
				<category><![CDATA[Cache]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[eaccelerator]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[php5-memcache]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[xcache]]></category>

		<guid isPermaLink="false">http://www.vvvegard.net/blog/?p=181</guid>
		<description><![CDATA[In this article I will focus on how to squeeze (No, not the SID/testing release of Debian) the last drop of juice from your Apache2-installation with small measurements, focusing on PHP performance. And if you&#8217;re really serious you might want to look into my articles about Varnish as well! Welcome to the world of caching [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I will focus on how to squeeze (No, not the SID/testing release of Debian) the last drop of juice from your Apache2-installation with small measurements, focusing on PHP performance. And if you&#8217;re really serious you might want to look into my articles about <a href="http://www.vvvegard.net/blog/category/varnish/" target="_blank">Varnish</a> as well! Welcome to the world of caching dynamic data! Not really, just some parts of it&#8230;<span id="more-181"></span></p>
<p>All the benchmarks in this article is based on Apache Benchmarking (ab) tool, so the numbers <strong>will not</strong> translate directly to a production environment. This was all done locally on a virtually hosted Debian Lenny (5.0.4) on VMWare Fusion. You should see much higher numbers than this in a real world scenario. If not you should highly consider buying a new server. The virtual server was running on a single 2,4Ghz shared core, with 1024MB virtually allocated memory and 8GB virtual drive.</p>
<p>For the actual tests i make ab run a series of 1000 requests with 10 concurrent requests at a time. In order for it to be a fair fight I run all tests twice. The page that is requested is a Pressflow-installation with a story consisting of three paragraphs of random bits and bytes, in total the document is 6755 bytes (very small). Apache is set up to respond to rewrites too, as most servers are.</p>
<p>My main configuration consists of Apache2, php5, phpmyadmin and mysql-server. In a production environment you might not need packages such as phpmyadmin and mysql-server, this is just installed for testing purposes. For bleeding edge packages i suggest taking a look at <a href="http://www.dotdeb.org/" target="_blank">dotdeb</a>, but i cannot vouch for the stability of said repository.</p>
<blockquote>
<pre>apt-get install apache2 php5 phpmyadmin mysql-server</pre>
</blockquote>
<p style="text-align: left;">With this fairly plain and simple setup up and running it&#8217;s time to crack some numbers. What we are focusing on is average request time, requests per second and time per request. On a basic Apache2 setup with default configuration and MPN Worker we get these numbers. You find the whole output at <a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a>.</p>
<blockquote>
<pre>Apache2 Default Configuration
Time taken for tests:   97.409 seconds
Requests per second:    10.27 [#/sec] (mean)
Time per request:       974.094 [ms] (mean)</pre>
</blockquote>
<p>From this we can read that we get around 10 req/s. This is not bad &#8211; <em>considering the setup</em> &#8211; but you&#8217;d want to see a lot more if you are to survive a sudden traffic rush, keep in mind that most of a sites traffic hits within a short time. Also, it took a whopping 974ms (on average, 10 concurrent!) to load each page. That almost 1 second, and that&#8217;s not counting in other factors such as network latency and the rendering speed of your visitors browser. This is just to actually get the damn data!</p>
<p>Moving on we&#8217;re going to try out some of the most popular opcode cachers for PHP. First of is my personal favorite, as before of writing this article, APC &#8211; Alternative PHP Cache.</p>
<blockquote>
<pre>apt-get intall php-apc
apt-cache show php-apc</pre>
</blockquote>
<p>As the last command shows us we&#8217;ve installed &#8220;Version: 3.0.19-2&#8243; of php-apc. This is the latest version of APC in the repository as of writing this. APC is very minimalistic in it&#8217;s design and does not require a lot of configuration to get it working. But we add the following line in order to beef it up a bit, you might want to experiment with this, depending on how many sites you host or how heavy the scripts are. Numbers are in MB, duh.</p>
<blockquote>
<pre>echo "apc.shm_size = 128" &gt;&gt; /etc/php5/conf.d/apc.conf
apache2ctl restart</pre>
</blockquote>
<p>Now that we&#8217;ve got that settled we move on to the actual benchmarking. As with Apache2 default configuration you can access the full benchmark at<a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a>. You will also find a <a href="http://static.vvvegard.net/files/benchmarking/config" target="_blank">sample configuration</a> here.</p>
<blockquote>
<pre>APC Default Configuration
Time taken for tests:   26.041 seconds
Requests per second:    38.40 [#/sec] (mean)
Time per request:       260.414 [ms] (mean)</pre>
</blockquote>
<p>We see a great improvement in time taken, requests served per second and the time it took per request. As we can see it&#8217;s almost 4 times faster with little to none actual work done.</p>
<p>Moving on we&#8217;re going to test a bit more advanced opcode cacher, XCache. It&#8217;s actually a side project from the super snappy and lightweight web server lighttpd but since is&#8217;s made for PHP it works with Apache2 to.</p>
<blockquote>
<pre>apt-get install php5-xcache
apt-cache show php5-xcache</pre>
</blockquote>
<p>The latest stable release in the repository is &#8220;Version: 1.2.2-3&#8243;. Like with APC I  did little modifications to the configuration shipped with Debian. Please note that XCache is a lot more flexible and secure because of it&#8217;s design; but also more complex and easier to break.</p>
<blockquote>
<pre>nano /etc/php5/conf.d/xcache.ini
Edit xcache.size to 128M</pre>
</blockquote>
<p style="text-align: left;">Just as with the others you find the complete benchmark at <a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a> and configurations in <a href="http://static.vvvegard.net/files/benchmarking/config">http://static.vvvegard.net/files/benchmarking/config</a>.</p>
<blockquote>
<pre>XCache Default Configuration
Time taken for tests:   25.523 seconds
Requests per second:    39.18 [#/sec] (mean)
Time per request:       255.233 [ms] (mean)</pre>
</blockquote>
<p>As we can see it&#8217;s only slightly faster than APC with a pretty basic configuration, but you should be able to squeeze a little more juice out of it by tuning the configuration a little more. Not groundbreakingly much faster than APC, but I guess the added flexibility might make XCache a better choice than APC.</p>
<p>Moving further along we hit the first obstacle, eAccelerator. It&#8217;s not in Debian Lenny repository, so we have to compile it from source. This will probably make eAccelerator much more up to date and some of the difference shown might be because of this. There are also people who have made their <a href="http://kevin.deldycke.com/2009/08/how-to-install-eaccelerator-php5-debian-lenny/" target="_blank">own packages</a> of this, use at own risk!</p>
<p>First we need to install some essentials for building a package form source. I will not get into detail in how to install and configure eAccelerator but if you run into any problems be sure to drop a line. These commands should do the magic! Please note that due to restrictions, (that you can remove) the maximum allowed shared memory under Linux Kernel 2.6 is 32MB so we run it on 32MB. This should not show any effects during this test as it&#8217;s a small site and not that much to actually cache, in bytes.</p>
<blockquote>
<pre>apt-get install build-essential autoconf automake libtool m4 php5-dev
wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
tar -xjvf eaccelerator-0.9.6.tar.bz2
phpize5
./configure
make; make install
cd /etc/php5/conf.d/
wget http://static.vvvegard.net/files/benchmark/config/eaccalerator.ini
mkdir /var/cache/eaccelerator
chmod 777 /var/cache/eaccelerator
apache2ctl restart</pre>
</blockquote>
<p>Like with XCache eAccelerator has a lot more flexible features than APC. There is a lot of tuning that can be done if you take your time. As with the rest you&#8217;ll find the complete benchmark at <a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a> and configurations at <a href="http://static.vvvegard.net/files/benchmarking/config">http://static.vvvegard.net/files/benchmarking/config</a>.</p>
<blockquote>
<pre>eAccelerator Default Configuration
Time taken for tests:   24.341 seconds
RRequests per second:    41.08 [#/sec] (mean)
Time per request:       243.408 [ms] (mean)</pre>
</blockquote>
<p style="text-align: left;">Here we see a marginal speed increase from both XCache and APC, but this might just be because if runs the latest available version of eAccelerator as of writing. You might also tweak eAccelerator a lot for more juice by visiting their <a href="http://eaccelerator.net/wiki/Settings" target="_blank">wiki</a> to get some good hint&#8217;s and tips. When it comes to security I guess eAccelerator is in for a beating, from my point of perspective you should not run this in a multi-user environment as users potentially can access and read each others PHP-files.</p>
<p style="text-align: left;">Moving yet again along we&#8217;re going to put php5-memcache up to the tests. Php5-memcache is a lot like APC with fewer possible configurations than XCache and eAccelerator. And like the others you find the complete benchmark at <a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a> and configurations in <a href="http://static.vvvegard.net/files/benchmarking/config">http://static.vvvegard.net/files/benchmarking/config</a>. We&#8217;re using the default configuration shipped with Debian, no modifications.</p>
<blockquote>
<pre>apt-get install php5-memcache
apt-cache show php5-memcache</pre>
</blockquote>
<p>We&#8217;re getting &#8220;Version: 3.0.1-1&#8243; of php5-memcache. This seems to be quite new as far as I could see. And that makes what comes next even more depressing.</p>
<blockquote>
<pre>php5-memcache Default Configuration
Time taken for tests:   98.439 seconds
Requests per second:    10.16 [#/sec] (mean)
Time per request:       984.391 [ms] (mean)</pre>
</blockquote>
<p>Woha! It&#8217;s actually worse than native PHP. This might be because of the configuration, but my gut feeling tells me there is something more in the grass, the server load went trough the roof with php5-memcache.</p>
<p>To sum it all up, most OPCode cachers do a really good job in both speeding up you requests and makes your server scale a little more than it does without any caching capability. Running a cacher is highly recommended as it reduces hits on your disks and makes your server scale a lot better. The tests also showed that most cachers make the server peak 4x as much on requests per second, witch should do the trick if you experience slowdown during peak hour on your server. In a combination with Varnish and a fine tuned setup you should be able to get around 150-200 req/s on backend servers while serving 1500+ req/s from Varnish, with a 90% cache-hit rate.</p>
<p>Next time I&#8217;ll make some nice graphs with rrdtool too <img src='http://www.vvvegard.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.vvvegard.net/blog/benchmarking-opcode-php-cachers-with-apache2-on-debian-lenny/181/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up nginx on Debian Lenny</title>
		<link>http://www.vvvegard.net/blog/setting-up-nginx-on-debian-lenny/132/</link>
		<comments>http://www.vvvegard.net/blog/setting-up-nginx-on-debian-lenny/132/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 22:49:59 +0000</pubDate>
		<dc:creator>Vegard Hansen</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://www.vvvegard.net/blog/?p=132</guid>
		<description><![CDATA[In this article i will i will focus on how to install, configure and setup Nginx. Nginx is a popular web server, load balancer and reverse caching proxy for many high traffic sites. Personally I prefer to use Apache2 with proper configuration and Varnish as frontend. In some cases you might want to use Nginx as frontend [...]]]></description>
			<content:encoded><![CDATA[<p>In this article i will i will focus on how to install, configure and setup Nginx. Nginx is a popular web server, load balancer and reverse caching proxy for many high traffic sites. Personally I prefer to use Apache2 with proper configuration and Varnish as frontend. In some cases you might want to use Nginx as frontend for compressing data after it has been received from the backend server, either to ease the load on the backend servers or because the backeds does not support this feature, as is the case with Varnish.<span id="more-132"></span></p>
<p>Please note that this is my first encounter with Nginx, so bare with me if I do some weird stuff. I try to document whatever I am doing, mostly to educate my self. You should not use any configuration found in this article in a production environment if you are not one hundred percent clear what it does and why it does it.</p>
<p>In this article we&#8217;ll install nginx from source as the latest stable release in Debian Lenny is very old. Please note that this <strong>might not</strong> be the case with Squeeze/SID, but in my articles I focus on using the latest stable release of Debian.</p>
<blockquote><p>apt-get install build-essential libpcre3-dev libpcre3 libssl-dev zlib1g-dev</p></blockquote>
<p>This will install all essential build utilities that you will need to build a program from source. In addition to this we install some libraries to support SSL and PECR to support rewrites.</p>
<blockquote>
<pre>cd /root
wget http://nginx.org/download/nginx-0.7.65.tar.gz
tar -zxvf nginx-0.7.65.tar.gz
cd nginx-0.7.65</pre>
</blockquote>
<p>Please go to <a href="http://nginx.org" target="_blank">nginx.org</a> and fetch the latest stable version of Nginx. As of writing this 0.7.65 is the latest stable release. We download it, untar it and move in to the folder. You probably knew this <img src='http://www.vvvegard.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  (4)</p>
<blockquote>
<pre>./configure --prefix=/usr/local /
--sbin-path=/usr/local/sbin /
--conf-path=/etc/nginx/nginx.conf /
--pid-path=/var/run/nginx.pid /
--error-log-path=/var/log/nginx/error.log /
--http-log-path=/var/log/nginx/access.log /
--with-http_ssl_module /
--with-debug</pre>
</blockquote>
<p>This tells the compiler where to put stuff and what modules we want to configure it with or without. Please refer to <a href="http://wiki.nginx.org/NginxInstallOptions" target="_blank">nginx wiki</a> if you want more prefixes. If you encounter any errors, read them and install whatever it is missing. Use some good old fashion Google-Fu! And please let me know in a comment if I made a Boo-Boo. (3)</p>
<blockquote>
<pre>make; make install</pre>
</blockquote>
<p>This uses the information given to it when we configured it and installs nginx. Normally this should go by without any errors as the step above should have found any short comings.</p>
<blockquote>
<pre>cd /etc/init.d/
wget http://static.vvvegard.net/files/nginx/nginx
chmod +x  nginx</pre>
</blockquote>
<p>This is a modified version of the startup script to comply with the special configuration we use. The original script can be found at <a href="http://articles.slicehost.com/2007/10/19/debian-etch-adding-an-nginx-init-script" target="_blank">articles.slicehost.com</a>. With this startup script you should be able to start, stop, restart or just reload it. I recommend you to visit the site that i snagged this startup script from, they have a lot of good articles on nginx and hosting in general! (2)</p>
<blockquote>
<pre>/etc/init.d/nginx start</pre>
</blockquote>
<p>This starts nginx and you should now be able to access it via your <a href="http://www.google.com/chrome" target="_blank">favorite browser</a>.</p>
<blockquote>
<pre>Server: nginx/0.7.65</pre>
</blockquote>
<p>This is the header that nginx puts out, and this verifies that nginx is actually serving us pages. I prefer to use Live HTTP Headers add-on for Firefox to inspect HTTP Headers.</p>
<blockquote>
<pre>cd /etc/nginx
mv nginx.conf old_nginx.conf
wget http://static.vvvegard.net/files/nginx/nginx.conf</pre>
</blockquote>
<p>This replaces the standard configuration to a modified version that comply with the standards of Debian. This is fairly basic and should work in most cases. (1)</p>
<blockquote><p>mkdir sites-enabled/<br />
cd sites-enabled/<br />
wget http://static.vvvegard.net/files/nginx/000-default</p></blockquote>
<p>Again, to comply with Debian standards we store all of our virtual hosts in it&#8217;s own folder and instead of including everyone manually we include everything in that folder with wildcard. (1)</p>
<blockquote>
<pre>/etc/init.d/nginx restart</pre>
</blockquote>
<p>Now this won&#8217;t do much, it will basically just serve static files located in &#8220;/var/www&#8221;. If we&#8217;d want PHP you&#8217;d have to either do it via fastcgi or use nginx as a frontend for Apache2, primarily for caching and compressing and let Apache2 handle all dynamic data.</p>
<p>Resources:<br />
(1) <a href="http://www.ubuntugeek.com/using-nginx-as-a-reverse-proxy-to-get-the-most-out-of-your-vps.html" target="_blank">http://www.ubuntugeek.com/using-nginx-as-a-reverse-proxy-to-get-the-most-out-of-your-vps.html</a><br />
(2) <a href="http://articles.slicehost.com/2007/10/19/debian-etch-installing-nginx" target="_blank">http://articles.slicehost.com/2007/10/19/debian-etch-installing-nginx</a><br />
(3) <a href="http://wiki.nginx.org/Main" target="_blank">http://wiki.nginx.org/Main</a><br />
(4) <a href="http://nginx.org/" target="_blank">http://nginx.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vvvegard.net/blog/setting-up-nginx-on-debian-lenny/132/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Varnish 2.0.6 on Debian Lenny</title>
		<link>http://www.vvvegard.net/blog/setting-up-varnish-2-0-6-on-debian-lenny/106/</link>
		<comments>http://www.vvvegard.net/blog/setting-up-varnish-2-0-6-on-debian-lenny/106/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 20:49:17 +0000</pubDate>
		<dc:creator>Vegard Hansen</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Varnish]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://www.vvvegard.net/blog/?p=106</guid>
		<description><![CDATA[Update 12.2001: Varnish-software.com now offers an official debian repo, you should use that instead of installing it via source. Check www.varnish-software.com for more information! Due to the strict rules of Debian many of the packages in stable releases are very old. In some cases though we want to run the latest version of a program, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 12.2001: Varnish-software.com now offers an official debian repo, you should use that instead of installing it via source. Check <a href="http://www.varnish-software.com">www.varnish-software.com</a> for more information!</strong></p>
<p>Due to the strict rules of Debian many of the packages in stable releases are very old. In some cases though we want to run the latest version of a program, mainly due to new features and increased speed. The latest version of Varnish under Debian Lenny&#8217;s repositories is 1.1.2 (apt-cache show varnish), but in most cases we&#8217;d want to run the latest, especially with rapidly developed programs like Varnish. Varnish 2.0.6 is alos available in the Debian repository for SID/Squeeze or via backports.</p>
<p><span id="more-106"></span></p>
<blockquote>
<pre>apt-get install build-essential</pre>
</blockquote>
<p>Now we got most of the essential stuff for building the packages under Debian Lenny.</p>
<blockquote>
<pre>cd /root
wget http://sourceforge.net/projects/varnish/files/varnish/2.0.6/varnish-2.0.6.tar.gz/download
tar -zxvf varnish-2.0.6.tar.gz
cd varnish-2.0.6/</pre>
</blockquote>
<p>Now we have fetched the (as of now) latest stable version of Varnish from the developers them selves. Moving on we configure it and install it.</p>
<blockquote>
<pre>./configure --prefix=/usr/local --sysconfdir=/etc --localstatedir=/var/lib --mandir=/usr/share/man
make
make install</pre>
</blockquote>
<p>This tells the compiler where to put stuff and then installs it. We&#8217;ve chosen most of the common places on Debian Lenny. This may vary on different operating systems. If you get any errors read them and install whatever it is missing. This should not be necessary if you remembered the first step.</p>
<blockquote>
<pre> ldconfig</pre>
</blockquote>
<p>This tells Debian to update the location of the libs. This is vital to get Varnish to work on Debian Linux. Failing to do this step will result in a &#8220;file not found&#8221; when trying to start Varnish. (2)</p>
<blockquote>
<pre>cp redhat/varnish.sysconfig /etc/default/varnish</pre>
</blockquote>
<p>This is the main varnish configuration file. This has nothing to do with how Varnish handles request but how the daemon is run. If you are unsure how to configure this just run with &#8220;Alternative 2&#8243;.</p>
<blockquote>
<div id="_mcePaste"><span style="font-family: Times; line-height: normal; font-size: small;"></p>
<pre>DAEMON_OPTS="-a &lt;out-side IP&gt;:80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -u varnish -g varnish \
             -s file,/var/lib/varnish/varnish_storage.bin,512M"</pre>
<p></span></div>
</blockquote>
<p>This is a pretty basic setup that listens to port 80. The control daemon runs on localhost:6082. This you can telnet into and get various stats, load/unload configuration files when Varnish is running. Very useful tool when tuning your Varnish configuration. Also, this setup uses a 512MB cache-file, this might be too high or to low for your site, depending on how much memory you have avaliable and how much content needs/can be cached.</p>
<blockquote>
<pre>nano /etc/varnish/default.vcl</pre>
</blockquote>
<p>This is where the main configuration is done. You should set it up with atleast one backend server. Personally i run Apache2 with appropriate tools as backends, but you may run any web server of your choice. Try running your backend servers locally bound to port 80, this way you can trick them into not rewriting url when Varnish forwards the requests to them. If you do this remember to bind Varnish to your out-side IP-address, or else you will not be able to bind two applications to the same port.</p>
<blockquote>
<pre>/usr/local/sbin/varnishd -f /etc/varnish/default.vcl</pre>
</blockquote>
<p>This will start Varnish, telling it to use the configuration file located in /etc/varnish/. If you did all your steps right you should be seeing something like this in your HTTP headers. You should make a startup-script for this if you are running it on a production server. (1)</p>
<blockquote>
<pre>X-Varnish: 1861896702
Age: 0
Via: 1.1 varnish</pre>
</blockquote>
<p>Now we&#8217;ve got a fully functioning setup of Varnish. Before you run this on a production site you may want to consult with the developers of Varnish to tune the installation to your needs. You should also make varnish run under it&#8217;s own user and group. Varnish does this by default but you have to actually add the user first.</p>
<blockquote>
<pre>adduser varnish --disabled-login --no-create-home</pre>
</blockquote>
<p>This should add the user.</p>
<p>Resources:<br />
(1) <a href="http://www.all2e.com/Ressourcen/Artikel-und-Fallstudien/Varnish-installation-and-setup-on-ez-publish-based-systems">http://www.all2e.com/Ressourcen/Artikel-und-Fallstudien/Varnish-installation-and-setup-on-ez-publish-based-systems</a><br />
(2) <a href="http://varnish-cache.org/changeset/4420">http://varnish-cache.org/changeset/4420</a><br />
(3) <a href="http://varnish-cache.org/">http://varnish-cache.org/</a><br />
(4) <a href="http://kristianlyng.wordpress.com/ ">http://kristianlyng.wordpress.com/ </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vvvegard.net/blog/setting-up-varnish-2-0-6-on-debian-lenny/106/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
