Railsをnginxで動かす。
nginxはロシア製のハイパフォーマンスなウェブサーバ。
評判が良いので試しに入れてrailsを動かしてみる。
[環境]
サーバ:さくらVSP
OS:CentOS 5.6 x86_64
[手順]
1.rvmをインストール
zsh < <(curl -s https://rvm.beginrescueend.com/install/rvm)
2.使用するrubyのバージョンを指定
$ rvm use 1.9.2-p180 $ rvm use 1.9.2-p180 --passenger
※rvmはApacheとNginxへのモジュールとしてpassengerが稼働するためのスクリプトを内包している。
3.passengerをgemでインストール
$ gem install passenger
4.passengerのnginex用モジュールのインストールコマンド実行
$ rvmsudo passenger-install-nginx-module
5.必要なライブラリーがインストールされいないためエラーメッセージが表示されたので
yumでインストール。
$ yum install curl-devel
5.再度、passengerのnginex用モジュールをインストール
※実行中に入力を求められるが、Nginxに特にモジュールを導入する必要がないので1を選択。
$ rvmsudo passenger-install-nginx-module
6.設定ファイル編集
serverセクションに server_name と root を設定。
$ vim /opt/nginx/conf/nginx.conf server { listen 80; server_name www.yourhost.com; root /somewhere/public; # <--- be sure to point to 'public'! passenger_enabled on; } >|| server_name=>使用するドメイン root=>railsのpublicディレクトリのパス。 これでnginxを起動すれば、passengerでrails3が稼働する。 7.起動スクリプト設定 >|?| $ cd /opt/ $ wget -O init-rpm.sh http://library.linode.com/assets/603-init-rpm.sh $ mv /opt/init-rpm.sh /etc/rc.d/init.d/nginx $ chmod +x /etc/rc.d/init.d/nginx $ chkconfig --add nginx $ chkconfig nginx on $ chkconfig nginx list
8.起動、停止確認
$ /etc/init.d/nginx start $ /etc/init.d/nginx stop