前提手順

rbenv - rails 環境作成

参考URL

nginxとPassengerでRailsアプリを動かしたよ - Umeyashikiの日記

手順

nginx Configuration options

1
2
3
4
5
# nginx -V
nginx: nginx version: nginx/1.1.7
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-51)
nginx: TLS SNI support disabled
nginx: configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/

gem install passenger (rbenv)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$ gem install passenger

$ cd ~/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/

$ tree -a  ~/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/bin

/home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/bin
|-- passenger
|-- passenger-config
|-- passenger-install-apache2-module
|-- passenger-install-nginx-module
|-- passenger-make-enterprisey
|-- passenger-memory-stats
`-- passenger-status

0 directories, 7 files

install nginx module

1
$ ./passenger-install-nginx-module 

1st

curl-devel が足りませんでした

 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
Welcome to the Phusion Passenger Nginx module installer, v3.0.11.

This installer will guide you through the entire installation process. It
shouldn't take more than 5 minutes in total.

Here's what you can expect from the installation process:

 1. This installer will compile and install Nginx with Passenger support.
 2. You'll learn how to configure Passenger in Nginx.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.

 --------------------------------------------

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * The 'make' tool... found at /usr/bin/make
 * A download tool like 'wget' or 'curl'... found at /usr/bin/wget
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /home/USER/.rbenv/versions/1.9.3-p0/bin/rake
 * rack... found
 * Curl development headers with SSL support... not found  #curl-devel がない
 * OpenSSL development headers... found
 * Zlib development headers... found

Some required software is not installed.
But don't worry, this installer will tell you how to install them.

Press Enter to continue, or Ctrl-C to abort.

--------------------------------------------

Installation instructions for required software

 * To install Curl development headers with SSL support:
   Please run yum install curl-devel as root.             #curl-devel をインストールしなさいね

If the aforementioned instructions didn't solve your problem, then please take
a look at the Users Guide:

  /home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/doc/Users guide Nginx.html
yum install curl-devel.x86_64
1
2
3
4
5
6
7
Installed:
  curl-devel.x86_64 0:7.15.5-9.el5_7.4                                                              

Dependency Installed:
  libidn-devel.x86_64 0:0.6.5-1.1                                                                   

Complete!

2nd

nginx re-install
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# diff -U0 ../nginx117/nginx_configure117.sh nginx_configure1112.sh
  --- ../nginx117/nginx_configure117.sh   2011-11-12 11:07:47.000000000 +0900
  +++ nginx_configure1112.sh      2012-01-08 00:26:47.000000000 +0900
  @@ -3,2 +3,2 @@
  -NGINX=nginx-1.1.7
  -SOURCE_DIR=/usr/local/src/NGINX/nginx117
  +NGINX=nginx-1.1.12
  +SOURCE_DIR=/usr/local/src/NGINX/nginx1112
  @@ -9,0 +10 @@
  +  --prefix='/usr/local/nginx' \
  @@ -23,0 +25,2 @@
  +  --with-cc-opt='-Wno-error' \
  +  --add-module='/home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/nginx' \

/usr/local/src/NGINX/nginx1112/nginx_configure1112.sh

./configure ごにょごにょ && make
 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
#!/bin/sh

NGINX=nginx-1.1.12
SOURCE_DIR=/usr/local/src/NGINX/nginx1112
id nginx || sudo useradd -s /sbin/nologin -d /usr/local/nginx -M nginx

cd $SOURCE_DIR/$NGINX 
[ -e "$SOURCE_DIR/$NGINX/Makefile" ] && make clean 
./configure \
  --prefix='/usr/local/nginx' \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_gzip_static_module \
  --with-http_realip_module \
  --http-log-path=/var/log/nginx/access.log \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  --with-cc-opt='-Wno-error' \
  --add-module='/home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/nginx' \
&& make
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# /usr/local/nginx/sbin/nginx -s stop

# cd /usr/local/src/NGINX/nginx1112/nginx-1.1.12
# make install

# /usr/local/nginx/sbin/nginx
# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.1.12
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-51)
TLS SNI support disabled
configure arguments: --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --with-cc-opt=-Wno-error --add-module=/home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/nginx

ここまではあんま関係ないですね。

さて rails が以下のように配置されていたとして

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
/path/to/rails_root
|-- Gemfile
|-- Gemfile.lock
|-- README
|-- Rakefile
|-- app
|-- config
|-- config.ru
|-- db
|-- doc
|-- lib
|-- log
|-- public
|-- script
|-- test
|-- tmp
`-- vendor

nginx の設定ファイルは以下のようにした。

/etc/nginx/conf.d/rails.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#rails.conf
    server {
        listen       80;
        server_name  aaa.to;
        access_log  /var/log/nginx/aaa.to/access.log  main;
        error_log  /var/log/nginx/aaa.to/error.log;

        location / {
          root /path/to/rails_root/public;
          passenger_enabled on;
          index index.html index.htm;
          rails_env development;
        }
    }
/etc/nginx/nginx.conf
 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
worker_processes  1;
events {
    worker_connections  1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

   #passenger
   passenger_root /home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11;
   passenger_ruby /home/USER/.rbenv/shims/ruby;
   #passenger

  #access_log  logs/access.log  main;

  sendfile        on;
  #tcp_nopush     on;

  #keepalive_timeout  0;
  keepalive_timeout  65;

  #gzip  on;

  server {
                listen       80;
    server_name  __default;
  }

  #include_zone
  include /etc/nginx/conf.d/rails.conf;
  #include_zone
}

うごいた!!