<?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>Matejunkie &#187; ruby on rails</title>
	<atom:link href="http://www.matejunkie.com/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.matejunkie.com</link>
	<description>&#34;Look behind you, a Three-Headed Monkey!&#34;</description>
	<lastBuildDate>Thu, 07 Jan 2010 14:26:10 +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>howto: nginx with php and Passenger (mod_rails) at once</title>
		<link>http://www.matejunkie.com/howto-nginx-with-php-and-passenger-mod_rails-at-once/</link>
		<comments>http://www.matejunkie.com/howto-nginx-with-php-and-passenger-mod_rails-at-once/#comments</comments>
		<pubDate>Tue, 19 May 2009 14:32:51 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[passenger (mod_rails)]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[spawn_fcgi]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=999</guid>
		<description><![CDATA[nginx is one hell of a webserver. It&#8217;s fast, efficient, small and reliable. According to  Netcraft&#8217;s webserver survey about 3 percent of world&#8217;s webserver are using nginx to deliver content and the amount of nginx-powered servers is growing strong. Since I was bothered by administrating another Apache (I do this all day long) and because [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-1011 alignleft" title="nginx-logo" src="http://www.matejunkie.com/wp-content/uploads/2009/05/nginx-logo.png" alt="nginx-logo" width="220" height="55" /><a title="Nginx - Official website" href="http://nginx.net/" target="_blank">nginx</a> is one hell of a webserver. It&#8217;s fast, efficient, small and reliable. According to  <a title="Netcraft - Webserver Survey" href="http://news.netcraft.com/archives/web_server_survey.html" target="_blank">Netcraft&#8217;s webserver survey</a> about 3 percent of world&#8217;s webserver are using nginx to deliver content and the amount of nginx-powered servers is growing strong.<br />
Since I was bothered by administrating another Apache (I do this all day long) and because I was tired of letting the Apache balance on several Mongrels which is not just slow, but also quite inefficient for this low-traffic blog, I just migrated my whole environment to be served by nginx. And that wasn&#8217;t much of a problem.</p>
<p>Here&#8217;s how I proceeded on a Debian Lenny server, enabling nginx to serve content via PHP and Ruby through <a title="Phusion Passenger - mod_rails" href="http://www.modrails.com/" target="_blank">Phusion&#8217;s Passenger</a>, also known as mod_rails, at once.</p>
<h3>Requirements</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># build-essential isn't installed by default, just in case you haven't done this yet</span>
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">bzip2</span> build-essential
<span style="color: #666666; font-style: italic;"># Required ruby packages</span>
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ruby ruby-dev ruby1.8 rubygems libopenssl-ruby
<span style="color: #666666; font-style: italic;"># FastCGI packages to make nginx work with PHP</span>
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libfcgi libfcgi-perl libfcgi
<span style="color: #666666; font-style: italic;"># The whole php5 package (you might not need all of it)</span>
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5 php5-cgi php5-common php5-dev php5-mysql php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-cgi php5-mcrypt php5-curl php5-gd php5-memcache php5-mhash php5-pspell php5-snmp php5-sqlite libmagick9-dev php5-cli</pre></div></div>

<h3>Get PHP going</h3>
<p>To enable nginx to serve PHP-written content we have to retrieve something from the <a title="Lighttpd" href="http://www.lighttpd.net/" target="_blank">lighttpd project</a> what is called spawnfcgi. This is necessary because nginx isn&#8217;t capable to handle PHP by default. We therefore have to get a copy of the lighttpd source, unpack, configure and make it. We then only copy the spawnfcgi binary to a local directory.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.lighttpd.net<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>lighttpd-1.4.18.tar.bz2
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">tar</span> xvjf lighttpd-1.4.18.tar.bz2
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #7a0874; font-weight: bold;">cd</span> lighttpd-1.4.18<span style="color: #000000; font-weight: bold;">/</span>
user<span style="color: #000000; font-weight: bold;">@</span>host ~<span style="color: #000000; font-weight: bold;">/</span>lighttpd-1.4.18 $ .<span style="color: #000000; font-weight: bold;">/</span>configure
user<span style="color: #000000; font-weight: bold;">@</span>host ~<span style="color: #000000; font-weight: bold;">/</span>lighttpd-1.4.18 $ <span style="color: #c20cb9; font-weight: bold;">make</span>
user<span style="color: #000000; font-weight: bold;">@</span>host ~<span style="color: #000000; font-weight: bold;">/</span>lighttpd-1.4.18 $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> src<span style="color: #000000; font-weight: bold;">/</span>spawn-fcgi <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>spawn-fcgi</pre></div></div>

<p>After that we should give it a try to see whether it&#8217;s working:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>spawn-fcgi <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi <span style="color: #660033;">-a</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">49232</span> <span style="color: #660033;">-P</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>fastcgi-php.pid
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">ps</span> aux<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> cgi
root     <span style="color: #000000;">31145</span>  <span style="color: #000000;">2.3</span>  <span style="color: #000000;">2.1</span> <span style="color: #000000;">191944</span> <span style="color: #000000;">11212</span> ?        Ss   <span style="color: #000000;">23</span>:<span style="color: #000000;">42</span>   <span style="color: #000000;">0</span>:00 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi
root     <span style="color: #000000;">31147</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.8</span> <span style="color: #000000;">191944</span>  <span style="color: #000000;">4676</span> ?        S    <span style="color: #000000;">23</span>:<span style="color: #000000;">42</span>   <span style="color: #000000;">0</span>:00 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi
root     <span style="color: #000000;">31148</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.8</span> <span style="color: #000000;">191944</span>  <span style="color: #000000;">4676</span> ?        S    <span style="color: #000000;">23</span>:<span style="color: #000000;">42</span>   <span style="color: #000000;">0</span>:00 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi</pre></div></div>

<p>We then kill the processes since we&#8217;ll write an init script which starts the spawner by default. First of all, we&#8217;re writing a simple shell script which makes the exact same call as above. Then we&#8217;re putting the init script below into /etc/init.d.</p>
<h4>/usr/bin/php5-fcgi</h4>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>spawn-fcgi <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi <span style="color: #660033;">-a</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">49232</span> <span style="color: #660033;">-C</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-P</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>fastcgi-php.pid</pre></div></div>

<h4>/etc/init.d/php5-fcgi</h4>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">PHP_SCRIPT</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php5-fcgi
<span style="color: #007800;">RETVAL</span>=<span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting fastcgi&quot;</span>
                <span style="color: #007800;">$PHP_SCRIPT</span>
                <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
        stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping fastcgi&quot;</span>
                <span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-9</span> php-cgi
                <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
        restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Restarting fastcgi&quot;</span>
                <span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-9</span> php-cgi
                <span style="color: #007800;">$PHP_SCRIPT</span>
                <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: php-fastcgi {start|stop|restart}&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$RETVAL</span></pre></div></div>

<p>Dont&#8217; forget to make both scripts executable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php5-fcgi
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>php5-fcgi</pre></div></div>

<p>To start the spawner during boot we&#8217;re putting its init script into the default runlevel:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> update-rc.d php5-fcgi defaults</pre></div></div>

<p>With the appropriate nginx configuration we&#8217;d be able to serve PHP content now, but before we&#8217;ll proceed we get Ruby going.</p>
<h3>Get Ruby going</h3>
<p>Since the deb package of rubygems only installs version 1.2.0, we have to upgrade it to at least 1.3.1. This has to be done manually since a &#8216;gem update &#8211;system&#8217; is disabled on Debian based distributions by default.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">45905</span><span style="color: #000000; font-weight: bold;">/</span>rubygems-1.3.1.tgz
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">tar</span> xzf rubygems-1.3.1.tgz
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #7a0874; font-weight: bold;">cd</span> rubygems-1.3.1<span style="color: #000000; font-weight: bold;">/</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~<span style="color: #000000; font-weight: bold;">/</span>rubygems-1.3.1 $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> ruby setup.rb</pre></div></div>

<p>After these steps, a &#8216;gem &#8211;version&#8217; should show that it&#8217;s upgraded to 1.3.1. So this has been done, we&#8217;re ready for installing passenger now:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> passenger</pre></div></div>

<p>That&#8217;ll do the job for the Ruby prerequisites. One more step is required before starting the passenger installer: creating directories.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>body
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>proxy
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>fastcgi</pre></div></div>

<p>We&#8217;re now ready to install nginx, but rather than installing it via aptitude we&#8217;ll compile it manually since otherwise passenger wouldn&#8217;t work. We&#8217;ll therefore download the source and then run the passenger installer since it&#8217;ll compile nginx for us after answering a couple of questions.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>sysoev.ru<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>nginx-0.6.36.tar.gz
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">tar</span> xzf nginx-0.6.36.tar.gz
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> passenger-install-nginx-module</pre></div></div>

<p>What now starts is an interactive dialogue which guides us through the passenger installation including the compilation of nginx and pcre as another requirement. After we&#8217;ve hit enter required software is being checked. If you&#8217;ve did the aptitude steps in the first place everything should be allright by now, but in case the installer bothers about something that&#8217;s missing, follow the steps provided by the installer. It&#8217;s self-explanatory.<br />
One more step and we&#8217;re asked to choose between two install methods. We choose 2 since we want to provide additional compile arguments before doing the actual work.</p>
<p>When we&#8217;re asked to provide the full path of the nginx source code, we type it in.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>nginx-0.6.36</pre></div></div>

<p>As the prefix we should rather choose /usr/local/nginx instead of /opt/nginx.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx</pre></div></div>

<p>Now comes the important part since we&#8217;re able to provide additional arguments before the actual compilation begins. nginx is highly configurable and versatile, it depends on your environment what you want to achieve. You might want to take a look at the <a title="nginx - Wiki" href="http://wiki.nginx.org/NginxModules" target="_blank">official nginx Wiki</a> to get information about the different modules. For me the following arguments did a good job.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">--user</span>=www-data 
<span style="color: #660033;">--group</span>=www-data 
<span style="color: #660033;">--sbin-path</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin 
<span style="color: #660033;">--conf-path</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>nginx.conf 
<span style="color: #660033;">--error-log-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>error.log 
<span style="color: #660033;">--pid-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.pid 
<span style="color: #660033;">--lock-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>nginx.lock 
<span style="color: #660033;">--http-log-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>access.log 
<span style="color: #660033;">--http-client-body-temp-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>body 
<span style="color: #660033;">--http-proxy-temp-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>proxy 
<span style="color: #660033;">--http-fastcgi-temp-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>fastcgi 
--with-http_ssl_module 
--with-http_dav_module 
--with-http_gzip_static_module 
--with-http_stub_status_module 
<span style="color: #660033;">--with-openssl</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib 
--without-mail_pop3_module 
--without-mail_smtp_module 
--without-mail_imap_module</pre></div></div>

<p>Copy&#8217;n'paste of the output above won&#8217;t work because of the line break. If you want to adopt the exact same arguments stick to the output below:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">--conf-path</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>nginx.conf <span style="color: #660033;">--error-log-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>error.log <span style="color: #660033;">--pid-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.pid <span style="color: #660033;">--lock-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>nginx.lock <span style="color: #660033;">--http-log-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>access.log <span style="color: #660033;">--http-client-body-temp-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>body <span style="color: #660033;">--http-proxy-temp-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>proxy <span style="color: #660033;">--http-fastcgi-temp-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>fastcgi --with-http_ssl_module --without-mail_pop3_module --without-mail_smtp_module --without-mail_imap_module <span style="color: #660033;">--sbin-path</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin <span style="color: #660033;">--user</span>=www-data <span style="color: #660033;">--group</span>=www-data --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module <span style="color: #660033;">--with-openssl</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib</pre></div></div>

<p>Pushing enter once more and nginx is finally getting compiled and installed. This usually won&#8217;t take more than 5 minutes and should return no error. After this the passenger installation provides additional information which can be ignored by now since you&#8217;ll find the exact same directives in the configuration output below.</p>
<h3>Get nginx going</h3>
<p>The first thing we&#8217;ll write is, of course, an init script. Copy&#8217;n'paste the output below into /etc/init.d/ and make it executable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and</span>
<span style="color: #666666; font-style: italic;"># run 'sudo update-rc.d nginx defaults', or use the appropriate command on your</span>
<span style="color: #666666; font-style: italic;"># distro.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Author:       Ryan Norbauer</span>
<span style="color: #666666; font-style: italic;"># Modified:     Geoffrey Grosenbach http://topfunky.com</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #007800;">DESC</span>=<span style="color: #ff0000;">&quot;nginx daemon&quot;</span>
<span style="color: #007800;">NAME</span>=nginx
<span style="color: #007800;">DAEMON</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>
<span style="color: #007800;">CONFIGFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>nginx.conf
<span style="color: #007800;">PIDFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid
<span style="color: #007800;">SCRIPTNAME</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Gracefully exit if the package has been removed.</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
d_start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">-c</span> <span style="color: #007800;">$CONFIGFILE</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot; already running&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
d_stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-QUIT</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$PIDFILE</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot; not running&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
d_reload<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-HUP</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$PIDFILE</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot; can't reload&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
        d_start
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
        d_stop
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Reloading <span style="color: #007800;">$DESC</span> configuration...&quot;</span>
        d_reload
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;reloaded.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Restarting <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
        d_stop
        <span style="color: #666666; font-style: italic;"># One second might not be time enough for a daemon to stop,</span>
        <span style="color: #666666; font-style: italic;"># if this happens, d_start will fail (and dpkg will break if</span>
        <span style="color: #666666; font-style: italic;"># the package is being upgraded). Change the timeout if needed</span>
        <span style="color: #666666; font-style: italic;"># be, or change d_stop to have start-stop-daemon use --retry.</span>
        <span style="color: #666666; font-style: italic;"># Notice that using --retry slows down the shutdown process somewhat.</span>
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">5</span>
        d_start
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: <span style="color: #007800;">$SCRIPTNAME</span> {start|stop|restart|force-reload}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
          <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">3</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx</pre></div></div>

<p>Now let&#8217;s create the Debian-like directory structure under /etc/nginx for different vhosts. This enables us to activate and deactivate vhosts the easy way via symlinking.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>What&#8217;s left is the actual configuration work of nginx. Please stick to the output below and make sure to read the comments with a leading #.<br />
One short note: I&#8217;m not that familiar with all the aspects of nginx&#8217;s configuration yet, but the configuration below works just fine. In case you find any flaws or tweaks, I&#8217;d be glad to know about them.</p>
<h4>/etc/init.d/nginx.conf</h4>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user  www-data;
worker_processes  <span style="color: #000000;">1</span>;
&nbsp;
events <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    worker_connections  <span style="color: #000000;">1024</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    include       mime.types;
    default_type  application<span style="color: #000000; font-weight: bold;">/</span>octet-stream;
&nbsp;
    sendfile        on;
    <span style="color: #666666; font-style: italic;">#tcp_nopush     on;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#keepalive_timeout  0;</span>
    keepalive_timeout  <span style="color: #000000;">65</span>;
&nbsp;
    <span style="color: #666666; font-style: italic;">#gzip  on;</span>
&nbsp;
    passenger_root <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.2;
    passenger_ruby <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby1.8;
&nbsp;
    include <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/*</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h4>/etc/init.d/sites-available/site-xyz</h4>
<p>The following is an example for a virtual server with PHP support enabled, including various location directives, e.g. for the status page of nginx which is only available when the status module has been compiled. If you took my compile arguments above, don&#8217;t worry, it&#8217;s integrated.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen   <span style="color: #000000;">80</span>;
        server_name  www.example.com;
&nbsp;
        access_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>access.log;
&nbsp;
        location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                root   <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>htdocs;
                index  index.php;
&nbsp;
                <span style="color: #666666; font-style: italic;"># this serves static files that exist without running other rewrite tests</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>-f <span style="color: #007800;">$request_filename</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                    expires 30d;
                    <span style="color: #7a0874; font-weight: bold;">break</span>;
                <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;"># this sends all non-existing file or directory requests to index.php</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>-e <span style="color: #007800;">$request_filename</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                    rewrite ^<span style="color: #7a0874; font-weight: bold;">&#40;</span>.+<span style="color: #7a0874; font-weight: bold;">&#41;</span>$ <span style="color: #000000; font-weight: bold;">/</span>index.php?<span style="color: #007800;">q</span>=$<span style="color: #000000;">1</span> <span style="color: #c20cb9; font-weight: bold;">last</span>;
                <span style="color: #7a0874; font-weight: bold;">&#125;</span>
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        location ~ .php$ <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                fastcgi_pass   127.0.0.1:<span style="color: #000000;">49232</span>; <span style="color: #666666; font-style: italic;">#this must point to the socket spawn_fcgi is running on.</span>
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME    <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #007800;">$fastcgi_script_name</span>;  <span style="color: #666666; font-style: italic;"># same path as above</span>
&nbsp;
                fastcgi_param  QUERY_STRING       <span style="color: #007800;">$query_string</span>;
                fastcgi_param  REQUEST_METHOD     <span style="color: #007800;">$request_method</span>;
                fastcgi_param  CONTENT_TYPE       <span style="color: #007800;">$content_type</span>;
                fastcgi_param  CONTENT_LENGTH     <span style="color: #007800;">$content_length</span>;
&nbsp;
                fastcgi_param  SCRIPT_NAME        <span style="color: #007800;">$fastcgi_script_name</span>;
                fastcgi_param  REQUEST_URI        <span style="color: #007800;">$request_uri</span>;
                fastcgi_param  DOCUMENT_URI       <span style="color: #007800;">$document_uri</span>;
                fastcgi_param  DOCUMENT_ROOT      <span style="color: #007800;">$document_root</span>;
                fastcgi_param  SERVER_PROTOCOL    <span style="color: #007800;">$server_protocol</span>;
&nbsp;
                fastcgi_param  GATEWAY_INTERFACE  CGI<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span>;
                fastcgi_param  SERVER_SOFTWARE    nginx<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$nginx_version</span>;
&nbsp;
                fastcgi_param  REMOTE_ADDR        <span style="color: #007800;">$remote_addr</span>;
                fastcgi_param  REMOTE_PORT        <span style="color: #007800;">$remote_port</span>;
                fastcgi_param  SERVER_ADDR        <span style="color: #007800;">$server_addr</span>;
                fastcgi_param  SERVER_PORT        <span style="color: #007800;">$server_port</span>;
                fastcgi_param  SERVER_NAME        <span style="color: #007800;">$server_name</span>;
&nbsp;
                <span style="color: #666666; font-style: italic;"># required if PHP was built with --enable-force-cgi-redirect</span>
                <span style="color: #666666; font-style: italic;"># fastcgi_param  REDIRECT_STATUS    200;</span>
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># this location directive only works if compiled with the status module</span>
        location <span style="color: #000000; font-weight: bold;">/</span>nginx_status <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                stub_status on;
                access_log   off;
                allow all;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>This is an example of a vhost configuration for a ruby powered vhost. As you can see the configuration here is much more straight-forward. Make sure that the root directive points to a directory of your project that&#8217;s called public.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen   <span style="color: #000000;">80</span>;
        server_name  www.example.com;
&nbsp;
        access_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>access.log
&nbsp;
        root <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #000000; font-weight: bold;">/</span>site-xyz<span style="color: #000000; font-weight: bold;">/</span>public;
        passenger_enabled on;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Afterwards simply symlink the configuration from /sites-enabled to /sites-available and start nginx. If everything&#8217;s ok you may see nginx&#8217;s default website and be ready to add your own PHP and Ruby applications.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-enabled $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>site-xyz site-xyz</pre></div></div>

<p>If you&#8217;ve got questions or suggestions, don&#8217;t hesitate to start a discussion. I&#8217;m looking forward to improve this guide if it didn&#8217;t help you with the installation and configuration of nginx. The idea of using spawn_fcgi and the init script for it comes <a title="ElasticDog - Howto install wordpress on Nginx" href="http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx/" target="_blank">from ElasticDog.com</a>, the init script for nginx has been written by Ryan Norbauer and modified by <a title="nor - nuby on rails" href="http://nubyonrails.com/" target="_blank">Geoffrey Grosenbach</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/howto-nginx-with-php-and-passenger-mod_rails-at-once/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
