Passengerを使ってRailsアプリケーションを複数動かす
Railsでなんか作ってサーバーで動かしたいなあと思ってるのでその下準備を。
OSはUbuntu12.04Serverです。
サーバーへのRailsのインストールはRails本番環境構築ガイドが詳しいです。
app.example.comというサブドメインをRailsで遊ぶために割り当てます。DNSレコードの設定はお名前.comだと簡単に済ませられます。
hogeというアプリを作った場合、app.hoge.com/hogeで動くように設定していきます。
Passengerの設定
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/ext/apache2/mod_passenger.so PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19 PassengerRuby /usr/local/bin/ruby
Apacheの設定
設定ファイル<VirtualHost *:80> ServerName app.example.com #Railsアプリケーションを動かすドメイン。ご自由に。 DocumentRoot /var/www/rails #シンボリックリンクを張っておくディレクトリ。適当に。 <Directory /var/www/rails> Options Includes ExecCGI FollowSymLinks MultiViews AllowOverride all DirectoryIndex index.html index.php index.py inedx.cgi index.shtml Order allow,deny allow from all </Directory> LogLevel warn ErrorLog ${APACHE_LOG_DIR}/rails-error.log CustomLog ${APACHE_LOG_DIR}/rails-access.log combined env=!no_log #アプリ毎の設定 <Directory /var/www/rails/hoge> RailsBaseURI /hoge RailsEnv development </Directory> <Directory /var/www/rails/fuga> RailsBaseURI /fuga RailsEnv development </Directory> </VirtualHost>
設定の有効化
sudo a2ensite app sudo service apache2 reload
作成したRailsのアプリケーションのpublicディレクトリのシンボリックリンクを、DocumentRootに指定したディレクトリに置けば動くはず。
RailsEnvのとこを、developmentからproductionにすれば本番環境として動かせます。
参考