LoginSignup
22

More than 5 years have passed since last update.

[Gehirn RS2] RVM+nginx+Passenger環境でRails3を動かしてみる

Last updated at Posted at 2012-12-24

Gehrn RS2でnginx+Passengerを使う際のインストールメモ。

2012/12/25 gemsetを使うようにしたため修正

ディスク容量を減らすため、facerootは使ってません。
まずは、SSHでログインします。
1.rubyをrs2コマンドでインストール

$ rs2 install ruby
※、インストール完了後、SSHで再ログインすると、RVMが設定されています。
ここで、gemsetを指定します。
$ rvm gemset create gehirn
$ rvm gemset use gehirn

2.gemrcの設定

$ vi ~/.gemrc
※、新規ファイルに以下を追加
:verbose: true
:sources: 
- http://gems.rubyforge.org/
- http://gems.github.com
:benchmark: false
:backtrace: false
:update_sources: true
:bulk_threshold: 1000
install: --no-ri --no-rdoc
update: --no-ri --no-rdoc

3.passengerをインストール

$ gem install passenger
※、passengerがインストールされます

4.nginxとmoduleをインストール

$ passenger-install-nginx-module
※、ここで1つ目の選択肢では「1」を2つ目の選択肢のインストールパスでは
「/home/[ユーザ名]/nginx」を指定します。

5.confファイルの設定
$ vi /home/[ユーザ名]/nginx/conf/nginx.conf
※、ここで、以下の設定を変更します。

変更前

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

変更後


    server {
        listen       61229;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/[ユーザ名]/nginx/html/[アプリディレクトリ]/public;
            #index  index.html index.htm;
            passenger_enabled on;
            passenger_base_uri /[アプリディレクトリ];
            rails_spawn_method smart;
            rails_env production;
        }

6.nginxの起動

$ cd /home/[ユーザ名]/nginx/sbin
$ ./nginx

これで、nginxが起動します。
ここで、アプリディレクトリにrailsのアプリを展開すればOKです。
展開時にBundlerについては、gemsetで設定しているのでsystemにインストールします。

アプリディレクトリで、以下を実施
$ vi .rvmrc
rvm gemset use ruby-1.9.3-p327@gehirn
※、rvmのgemsetを指定

$ bundle install --system
※、gemをインストール

$ bundle exec rake assets:precompile 
※、sssetsをコンパイル

7.index.htmlの削除

$ rm /home/[ユーザ名]/nginx/html/index.html

8.Passengerの再起動

$ touch /home/[ユーザ名]/nginx/html/[アプリディレクトリ]/tmp/restart.txt

問題がなければ、以下のアドレスにアクセスすれば、Railsアプリが実行されています。
http://ユーザ名.gehirn.ne.jp:61229/

サービスとして登録するのではなく、cronの@restartなどに起動シェルを登録して
再起動に対応します。(このへんは別途記載)

3.50 GB 中 478.49 MB(13%)使用しています。

と少ないので個人的にはありと思っております。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22