<?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>Ruby, Rails, OSX and Linux fun &#187; nginx</title>
	<atom:link href="http://www.frederico-araujo.com/tag/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederico-araujo.com</link>
	<description>Ruby, Rails, OSX and linux sysadmin</description>
	<lastBuildDate>Thu, 02 Sep 2010 08:13:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Easy installing Nginx + mod_rails passenger OSX</title>
		<link>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/</link>
		<comments>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 18:39:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[nginx]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[mod_rails]]></category>
		<category><![CDATA[passenger]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=92</guid>
		<description><![CDATA[Requirements:
1. XCODE  you can download xcode from http://developer.apple.com/tools/xcode/index.html
2. OSX 10.4, 10.5 or 10.6
Procedures:
1. Install Passenger
$ sudo gem install passenger
now check where is passenger installed:

$ passenger-config --root

in my case is: /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5
2. Install nginx
If you have nginx from macports, deactivate it in case of conflicts.
You can activate anytime later
$ sudo port deactivate nginx
$ wget http://sysoev.ru/nginx/nginx-0.7.59.tar.gz
$ wget [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Requirements</strong>:</p>
<p>1. XCODE  you can download xcode from <a href="http://developer.apple.com/tools/xcode/index.html">http://developer.apple.com/tools/xcode/index.html</a></p>
<p>2. OSX 10.4, 10.5 or 10.6</p>
<p><strong>Procedures</strong>:</p>
<p><strong>1. Install Passenger</strong></p>
<p>$ sudo gem install passenger</p>
<p>now check where is passenger installed:</p>
<pre>
$ passenger-config --root
</pre>
<p>in my case is: /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5</p>
<p><strong>2. Install nginx</strong></p>
<p>If you have nginx from macports, deactivate it in case of conflicts.</p>
<p>You can activate anytime later</p>
<p>$ sudo port deactivate nginx</p>
<p><del datetime="2009-06-16T13:04:06+00:00">$ wget http://sysoev.ru/nginx/nginx-0.7.59.tar.gz</p>
<p>$ wget http://sysoev.ru/nginx/nginx-0.7.62.tar.gz</p>
<p>$ tar xpf nginx-0.7.62.tar.gz</p>
<p>$ cd nginx-0.7.62</p>
<p></del></p>
<p><del datetime="2009-09-23T22:31:19+00:00">
<p>I Recommend using nginx 0.6 series because I had a lot of  &#8220;502 Bad Gateway&#8221; with 0.7 series. </p>
<p>$ wget http://sysoev.ru/nginx/nginx-0.6.37.tar.gz</p>
<p>$ tar xpf nginx-0.6.37.tar.gz</p>
<p>$ cd nginx-0.6.37<br />
</del></p>
<pre>
$ sudo ./configure --add-module=/opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/nginx/ \
  --with-http_ssl_module --user=nobody --group=nobody --with-http_gzip_static_module \
  --with-poll_module --prefix=/opt/local --with-pcre
</pre>
<pre>
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1 library is not used
+ using system zlib library

nginx path prefix: "/opt/local"
nginx binary file: "/opt/local/sbin/nginx"
nginx configuration prefix: "/opt/local/conf"
nginx configuration file: "/opt/local/conf/nginx.conf"
nginx pid file: "/opt/local/logs/nginx.pid"
nginx error log file: "/opt/local/logs/error.log"
nginx http access log file: "/opt/local/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
</pre>
<p>$ sudo make</p>
<p>$ sudo make install</p>
<p>$ cd /opt/local/conf</p>
<p>$ sudo cp mime.types.default mime.types</p>
<p>$ sudo cp nginx.conf.default nginx.conf</p>
<p><strong>Edit nginx.conf</strong></p>
<p>$ mate nginx.conf</p>
<p>or</p>
<p>$ sudo vi nginx.conf</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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">&nbsp;
<span style="color: #00007f;">user</span> nobody;
worker_processes  <span style="color: #ff0000;">2</span>;
&nbsp;
<span style="color: #adadad; font-style: italic;">#error_log  logs/error.log;</span>
<span style="color: #adadad; font-style: italic;">#error_log  logs/error.log  notice;</span>
error_log  logs/error.log  info;
&nbsp;
<span style="color: #adadad; font-style: italic;"># Pid</span>
pid  logs/nginx.pid;
&nbsp;
events {
worker_connections <span style="color: #ff0000;">1024</span>;
}
&nbsp;
http {
<span style="color: #00007f;">include</span>       mime.types;
default_type  application/octet-stream;
&nbsp;
sendfile        <span style="color: #0000ff;">on</span>;
<span style="color: #adadad; font-style: italic;">#tcp_nopush     on;</span>
&nbsp;
<span style="color: #adadad; font-style: italic;">#keepalive_timeout  0;</span>
keepalive_timeout  <span style="color: #ff0000;">65</span>;
&nbsp;
gzip  <span style="color: #0000ff;">on</span>;
<span style="color: #adadad; font-style: italic;"># if a precompiled gzip of the file exists, use it and force http proxies</span>
<span style="color: #adadad; font-style: italic;"># to use separate cache's based on User-Agent</span>
gzip_static <span style="color: #0000ff;">on</span>;
gzip_min_length <span style="color: #ff0000;">2000</span>;
gzip_buffers    <span style="color: #ff0000;">16</span> 8k;
gzip_types      text/plain text/html text/css image/x-icon application/xml application/xml+rss text/javascript;
gzip_disable    <span style="color: #7f007f;">&quot;MSIE [1-6] <span style="color: #000099; font-weight: bold;">\.</span>&quot;</span>;
gzip_vary         <span style="color: #0000ff;">on</span>;
gzip_comp_level   <span style="color: #ff0000;">2</span>;
&nbsp;
gzip_proxied any;
&nbsp;
server {
<span style="color: #00007f;">listen</span>       <span style="color: #ff0000;">80</span>;
server_name  localhost;
<span style="color: #00007f;">location</span> / {
root   /Users/fred/Sites ;
autoindex <span style="color: #0000ff;">on</span>;
index  index.html index.htm;
}
}
&nbsp;
passenger_root /opt/local/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.2.2;
passenger_max_pool_size <span style="color: #ff0000;">8</span>;
passenger_max_instances_per_app <span style="color: #ff0000;">1</span>;
<span style="color: #adadad; font-style: italic;"># The maximum number of seconds that an application instance may be idle.</span>
<span style="color: #adadad; font-style: italic;"># That is, if an application instance hasn’t received any traffic after the given number of seconds,</span>
<span style="color: #adadad; font-style: italic;"># then it will be shutdown in order to conserve memory.</span>
passenger_pool_idle_time <span style="color: #ff0000;">3600</span>;
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 1</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project1.local;
root /Users/fred/rails/project1/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project1/log/nginx.access.log;
error_log  /Users/fred/rails/project1/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 2</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project2.local;
root /Users/fred/rails/project2/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project2/log/nginx.access.log;
error_log  /Users/fred/rails/project2/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 3</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project3.local;
root /Users/fred/rails/project3/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project3/log/nginx.access.log;
error_log  /Users/fred/rails/project3/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># And so on... as many projects as you want</span>
&nbsp;
}</pre></td></tr></table></div>

<p>Now edit your /etc/hosts and add the hosts for your local project</p>
<p>$ mate /etc/hosts</p>
<pre>

127.0.0.1   project1.local

127.0.0.1   project2.local

127.0.0.1   project3.local
</pre>
<p><strong>3. Start nginx</strong></p>
<p>sudo nginx</p>
<p><strong>4. go to your browser and open project1.local</strong></p>
<p><strong> <img src='http://www.frederico-araujo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></p>
<p><strong>5. Easy start/restart/stop</strong></p>
<p>add this to your ~/.bash_profile file</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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_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: #007800;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Reloading NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-HUP</span> <span style="color: #007800;">$PID</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_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: #007800;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-INT</span> <span style="color: #007800;">$PID</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_restart<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;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-INT</span> <span style="color: #007800;">$PID</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting NGINX...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> nginx
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p><strong>Troubleshooting</strong></p>
<p>1. Nginx is not running</p>
<p>- check the logs</p>
<p>- check if it is really not running:</p>
<p>$ ps aux | grep nginx</p>
<p>2. you see the nginx error &#8220;502 Bad Gateway&#8221;</p>
<p>- may there is a problem with the /var/folders/ permissions on OSX:</p>
<pre>

2009/06/13 16:14:33 [crit] 1106#0: *1 connect() to unix:/var/folders/xl/xlSRYvzFHH8Fcehc51ciyE+++TI/-Tmp-//passenger.1091/master/helper_server.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: hassan.local, request: "GET / HTTP/1.1", upstream: "unix:/var/folders/xl/xlSRYvzFHH8Fcehc51ciyE+++TI/-Tmp-//passenger.1091/master/helper_server.sock:", host: "hassan.local"
</pre>
<p>to fix it I did this:</p>
<p>$ sudo find /var/folders/xl/ -name &#8220;master&#8221; -exec chmod 755 {} \;</p>
<p>$ sudo find /var/folders/xl/ -name &#8220;-Tmp-&#8221; -exec chmod 755 {} \;</p>
<p>everytime I reboot my mac I had to do that&#8230; I still dont know how to fix it&#8230;</p>
<p>anybody knows?</p>
<p>That is it for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
