以前「CentOS(6.3)にRuby(1.9)、Rails、Passengerをインストール」の記事で、PassengerとApacheを
試しましたが、今回はRubyもRVMでインストールし、PassengerもNginxで利用する形を試してみました。

○RVMのインストール

# curl -L https://get.rvm.io | bash -s stable
...

○Rubyのインストール

# /usr/local/rvm/bin/rvm install 1.9.3
...

○デフォルトのRubyの設定

# rvm use ruby-1.9.3 --default
Using /usr/local/rvm/gems/ruby-1.9.3-p392

○デフォルトのRubyのバージョン確認

# ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]

○Passengerのインストール

# gem install passenger
...

○依存パッケージのインストール

# yum -y install gcc gcc-c++ make curl-devel openssl-devel zlib-devel
...

○OpenSSL関係のビルド

# cd /usr/local/rvm/src/ruby-1.9.3-p392
# cd ext/openssl/
# ruby extconf.rb
...
# make
...
# make install
/usr/bin/install -c -m 0755 openssl.so /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/x86_64-linux
installing default openssl libraries

○Passenger対応Nginxのインストール

# passenger-install-nginx-module
...
* 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/curl
* Ruby development headers... found
* OpenSSL support for Ruby... found
* RubyGems... found
* Rake... found at /usr/local/rvm/wrappers/ruby-1.9.3-p392/rake
* rack... found
* Curl development headers with SSL support... found
* OpenSSL development headers... found
* Zlib development headers... found
...

下記でNginxのダウンロードからインストールも行います。

...
Automatically download and install Nginx?

Nginx doesn't support loadable modules such as some other web servers do,
so in order to install Nginx with Passenger support, it must be recompiled.

Do you want this installer to download, compile and install Nginx for you?

1. Yes: download, compile and install Nginx for me. (recommended)
The easiest way to get started. A stock Nginx 1.2.6 with Passenger
support, but with no other additional third party modules, will be
installed for you to a directory of your choice.

2. No: I want to customize my Nginx installation. (for advanced users)
Choose this if you want to compile Nginx with more third party modules
besides Passenger, or if you need to pass additional options to Nginx's
'configure' script. This installer will 1) ask you for the location of
the Nginx source code, 2) run the 'configure' script according to your
instructions, and 3) run 'make install'.

Whichever you choose, if you already have an existing Nginx configuration file,
then it will be preserved.

Enter your choice (1 or 2) or press Ctrl-C to abort: 1
...

以上で/opt/nginx以下にPassengerに対応したNginxがインストールされます。
設定ファイルは、すでに下記のようになっています。

# cat /opt/nginx/conf/nginx.conf
...
http {
...
passenger_root /usr/local/rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.3-p392/ruby;
...
}
....

そして、Ruby on Railsを利用する場合は、次のように設定すれば大丈夫なようです。

server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public;
passenger_enabled on;
}

こちらの記事はなかの人(suz-lab)監修のもと掲載しています。
元記事は、こちら