Mongrel + Apacheの連携

MongrelApacheを連携させてRailsアプリケーションを動かす。
まずはMongrelをインストールする。


# gem install mongrel
Mongrelをインストールすると、script/serverスクリプトMongrelが起動するようになる。
script/serverコマンドは以下のように起動するサーバを指定できる。

# ruby script/server webrick
サーバを指定しない場合は、以下の優先順位を元に起動するサーバを決定する。

  1. Mongrel
  2. Lighttpd
  3. WEBrick

よってMongrelをインストール後もscript/serverスクリプトを使えるが、
Mongrel専用の起動スクリプトを使うとscript/serverスクリプトには無いオプションを使うことが出来る。


# mongrel_rails start --prefix /myapp
のようにprefixオプションを使うと、http://localhost:3000/myappがアプリケーションルートになる。
アプリケーションごとに異なるprefixをつければ、ドメインが一つしかない場合でも手軽に複数のRailsアプリケーションを公開することが出来る。

Apacheの設定

設定ファイルhttpd-proxy.confを新規作成する。


# vi /usr/local/httpd-2.2.9/conf/extra/httpd-proxy.conf
以下を記述

ProxyRequests Off


Order deny,allow
Allow from all

ProxyPass /webdav !
ProxyPass / http://localhost:3000/

httpd.confに以下の記述を追加する。

# Proxy
Include conf/extra/httpd-proxy.conf