開発するうえで調べたこと、知ったことを備忘録としてメモメモ!

Windows環境でApache+MongrelでRailsを動かす

MongrelっていうのはWEBrick互換のサーバプログラムらしい。
Apache をリバースプロキシとして動作させ、Rails アプリケーションへのリクエストを Mongrel にプロキシする。

まずはそれぞれのバージョン
  • Apache 2.2.17
  • ruby 1.8.7 (2011-12-28 patchlevel 357) [i386-mingw32]
  • Rails 2.3.14
  • mongrel (1.1.5 x86-mingw32)

手順

1.mongrel_serviceのインストール
F:\dev\ruby\workspace\practice>gem install mongrel_service
Successfully installed gem_plugin-0.2.3
Successfully installed cgi_multipart_eof_fix-2.5.0
Successfully installed mongrel-1.1.5-x86-mingw32
Successfully installed mongrel_service-0.4.0
4 gems installed
Installing ri documentation for gem_plugin-0.2.3...
Installing ri documentation for cgi_multipart_eof_fix-2.5.0...
Installing ri documentation for mongrel-1.1.5-x86-mingw32...
Installing ri documentation for mongrel_service-0.4.0...
Installing RDoc documentation for gem_plugin-0.2.3...
Installing RDoc documentation for cgi_multipart_eof_fix-2.5.0...
Installing RDoc documentation for mongrel-1.1.5-x86-mingw32...
Installing RDoc documentation for mongrel_service-0.4.0...

2.mongrelの起動確認
F:\dev\ruby\workspace\practice>mongrel_rails start
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  INT => stop (no restart).
** Mongrel 1.1.5 available at 0.0.0.0:3000
** Use CTRL-C to stop.
ちなみにWEBrickを起動させるときのように
ruby script/server
でも起動できる。
mongrelをインストールすると勝手に切り替わるようだ。
こちらで起動した方が
  • リダイレクトがされない。
  • 詳細画面でエラーになる。
  • Content-Type text/plainになってしまう。
  • レスポンスが返ってこない場合ある。
などの不具合が起きなくなった。

3.Apacheの設定
リバースプロキシとして設定するので
httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
これらがコメントされていたら外す。

今回はVirtualHostを使っているのでhttpd-vhost.confに以下を設定。
httpd-vhost.conf
<VirtualHost *:80>
    ServerAdmin practice@ruby.localhost
    DocumentRoot "F:\dev\ruby\workspace\practice\public"
    ServerName ruby.localhost
    ServerAlias www.ruby.localhost
    ##ErrorLog "logs/dummy-host2.localhost-error.log"
    ##CustomLog "logs/dummy-host2.localhost-access.log" combined
    
    <IfModule mod_proxy.c>
        <Proxy *>
                Order deny,allow
                allow from all
        </Proxy>

        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://localhost:3000/
    </IfModule>
</VirtualHost>
Apacheの再起動。

これで本来Mongrelにhttp://localhost:3000/でアクセスしてたのをhttp://ruby.localhost/でアクセスできるようになった。
ブサイクなポート指定をわざわざしなくてOKになった。
タグ

このページへのコメント

uGfcGS <a href="http://dcrjedmikidh.com/">dcrjedmikidh</a>, [url=http://hmxfiqlhbqxa.com/]hmxfiqlhbqxa[/url], [link=http://qqoawocthqxv.com/]qqoawocthqxv[/link], http://ouaxxkctqcdr.com/

0
Posted by quwkyrcqu 2013年07月07日(日) 09:28:23 返信

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

メンバーのみ編集できます