<?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>unsignedint &#187; English</title>
	<atom:link href="http://unsignedint.net/blog/category/english/feed/" rel="self" type="application/rss+xml" />
	<link>http://unsignedint.net/blog</link>
	<description>adding noise to the signal</description>
	<lastBuildDate>Sat, 10 Jul 2010 10:32:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Installing nginx and rails passenger on Mac OS X Snow Leopard</title>
		<link>http://unsignedint.net/blog/2009/10/17/installing-nginx-and-rails-passenger-on-mac-os-x-snow-leopard/</link>
		<comments>http://unsignedint.net/blog/2009/10/17/installing-nginx-and-rails-passenger-on-mac-os-x-snow-leopard/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 11:07:50 +0000</pubDate>
		<dc:creator>lmmendes</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.unsignedint.net/blog/?p=170</guid>
		<description><![CDATA[I&#8217;m new to Mac OS X, nginx and rails so after much goggling i finally got everything to work so i resolved to compile the list of instructions that i followed. First we need to download, compile and install PRE (Perl Compatible Regular Expressions) it&#8217;s required for nginx. You can find the most recent version [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m new to Mac OS X, nginx and rails so after much goggling i finally got everything to work so i resolved to compile the list of instructions that i followed.</p>
<p>First we need to download, compile and install PRE (Perl Compatible Regular Expressions) it&#8217;s required for nginx. You can find the most recent version here http://www.pcre.org/ , at time of writing this post the most recent version is 7.9</p>
<p>Compiling and installing PRE</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>src
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>src
curl <span style="color: #660033;">-O</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>ftp.csx.cam.ac.uk<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>software<span style="color: #000000; font-weight: bold;">/</span>programming<span style="color: #000000; font-weight: bold;">/</span>pcre<span style="color: #000000; font-weight: bold;">/</span>pcre-<span style="color: #000000;">7.9</span>.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> pcre-<span style="color: #000000;">7.9</span>.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> pre-<span style="color: #000000;">7.9</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Installing Phusion Passenger via gem</p>

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

<p>Now that you have Phusion Passenger installed you can install and configure nginx and passenger using a bundled script from passenger called &#8220;passenger-install-nginx-module&#8221; but that is no fun and usually don&#8217;t install the lasted stable version of nginx, so you can run the script and follow it&#8217;s instructions (that include auto-downloading and installing of nginx) or do it my way&#8230; the hard way.</p>
<p>So now we need to find where &#8220;gem&#8221; installed the nginx module so we can refer to it&#8217;s during the nginx configuration, so to get the module path you just need to run this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">passenger-config <span style="color: #660033;">--root</span></pre></td></tr></table></div>

<p>In my case the command output is</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/&lt;</span>usename<span style="color: #000000; font-weight: bold;">&gt;/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<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.5</pre></td></tr></table></div>

<p>You need to write down this output, you will need it in the next step.</p>
<p>Now it&#8217;s time do download and install nginx we will be installing version 0.7.62 (stable).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>src
curl <span style="color: #660033;">-O</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.7.62.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> nginx-0.7.62.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> nginx-0.7.62
.<span style="color: #000000; font-weight: bold;">/</span>configure \
<span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span> \
<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;">--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;">--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;">--http-client-body-temp-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>client \
<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>tmp<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>tmp<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>fastcgi \
<span style="color: #660033;">--with-md5-asm</span> <span style="color: #660033;">--with-md5</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include \
<span style="color: #660033;">--with-sha1-asm</span> \
<span style="color: #660033;">--with-sha1</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include \
--with-http_realip_module \
--with-http_ssl_module \
--with-http_stub_status_module \
<span style="color: #660033;">--add-module</span>=<span style="color: #ff0000;">'/Users/&lt;username&gt;/.gem/ruby/1.8/gems/passenger-2.2.5/ext/nginx'</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Has you can see in line <strong>20</strong> you need to add the previous output that i told you to write down.</p>
<p>The nginx install path&#8217;s, bin, etc&#8230; :</p>
<p>bin: /usr/local/sbin/nginx<br />
etc: /etc/nginx/<br />
pid: /var/run/nginx.pid<br />
document root: /usr/local/html/<br />
error log: /var/log/nginx/error_log</p>
<p>Now let&#8217;s create a demo rails application to show things working</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">rails ~<span style="color: #000000; font-weight: bold;">/</span>Sites<span style="color: #000000; font-weight: bold;">/</span>blog</pre></td></tr></table></div>

<p>Edit /etc/nginx/nginx.conf (you can use your favorit text editor, i will be using vi)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vi</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</pre></td></tr></table></div>

<p>Find the &#8220;http&#8221; section and add this lines</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">passenger_root <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<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.5;
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>ruby;</pre></td></tr></table></div>

<p>You should get something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">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;
    passenger_root <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<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.5;
    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>ruby;
. . . .</pre></td></tr></table></div>

<p>Now adding the virtual host to nginx.conf to run ~/Sites/blog app ( /Users/<username>/Sites/blog )</p>
<p>Add a new server configuration (vhost) inside the http section of the nginx.conf file like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">  server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
          passenger_enabled on;
          listen <span style="color: #000000;">80</span>;
          server_name blog;
          root <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;/</span>Sites<span style="color: #000000; font-weight: bold;">/</span>blog<span style="color: #000000; font-weight: bold;">/</span>public;
          rails_env development;
  <span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>Now save the file and let&#8217;s se if it&#8217;s all working.</p>
<p>Start the nginx like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><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>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>nginx</pre></td></tr></table></div>

<p>Let&#8217;s edit the /etc/host file to add the new vhost name ( blog )</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hosts</pre></td></tr></table></div>

<p>add this to the bottom of the file, save and exit</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">127.0.0.1       blog</pre></td></tr></table></div>

<p>Now point your browser to <strong>http://blog</strong> and you should the the standard rails app page if you experince any problem starting nginx use this command to see nginx error log</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</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</pre></td></tr></table></div>

<p>All done, i hope it helps you.</p>
<div class="shr-publisher-170"></div>]]></content:encoded>
			<wfw:commentRss>http://unsignedint.net/blog/2009/10/17/installing-nginx-and-rails-passenger-on-mac-os-x-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

