«前の日記(2006-04-15(Sat)) 最新 次の日記(2006-04-19(Wed))» 編集

これ日記なん?


2006-04-16(Sun) [長年日記]

_ [Rails]Ajp-Railsを試す

以下の環境で試して動いたヽ(´ー`)ノ

  • ruby1.8.4(ASR1.8.4.0)
  • ajp-rails (0.1.0)
  • Apache2.0.55(win32)
  • mod_jk(1.2.15)
  • rails(rev 4206)

インスコ

> gem install ajp-rails -y

httpd.conf

include "c:/home/www/conf.d/*.conf"

mod_jk.conf

<IfModule !mod_jk.c>
  LoadModule jk_module "C:/Program Files/Apache Group/Apache2/modules/mod_jk.so"
  JkWorkersFile "c:/home/www/conf.d/workers.properties"
  JkLogFile "c:/home/www/logs/mod_jk.log"
  JkLogLevel info
  JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
  JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
  JkRequestLogFormat "%w %V %T"

  JkMount /ajp-mounted/* ajprails
</IfModule>
Alias /todo "c:/home/kog/prj/todo/public"
<Directory "c:/home/kog/prj/todo/public">
  Options ExecCGI FollowSymlinks
  AllowOverride All
</Directory>

workers.properties

# Comma separated worker names
worker.list=jkstatus,ajprails
# Definition for Ajp13 worker
#
worker.ajprails.type=ajp13
worker.ajprails.port=3009
worker.ajprails.host=localhost
worker.jkstatus.type=status

public/.htaccess

RewriteEngine On
RewriteBase /todo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /ajp-mounted/$1 [QSA,L]
RewriteRule ^([^.]+)$ $1.html [QSA]
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

config/production.rb

ActionController::AbstractRequest.relative_url_root = '/todo'

config/ajp.yaml

host: localhost
port: 3009
location: /todo
prefix: /ajp-mounted
directory: "c:/home/kog/prj/todo"

パッチ(!)

--- ajp_rails_dispatcher.rb.orig	2006-04-15 23:58:12.904643200 +0900
+++ ajp_rails_dispatcher.rb	2006-04-16 02:30:28.410856000 +0900
@@ -15,18 +15,18 @@
       response = AjpRailsResponse.new
       prepare_application
       ActionController::Routing::Routes.recognize!(request).process(request, response)
-      ajp_req.output_cookies.each do |cookie|
-        if cookie.name == 'JSESSIONID'
-	  case cookie.value
-	  when String
-	    cookie.value << '.' << server_environments['LOAD_BALANCE_ID']
-	  when Array
-	    cookie.value.each do |item|
-	      item << '.' << server_environments['LOAD_BALANCE_ID']
-	    end
-	  end
-	end
-      end
+#      ajp_req.output_cookies.each do |cookie|
+#        if cookie.name == 'JSESSIONID'
+#	  case cookie.value
+#	  when String
+#	    cookie.value << '.' << server_environments['LOAD_BALANCE_ID']
+#	  when Array
+#	    cookie.value.each do |item|
+#	      item << '.' << server_environments['LOAD_BALANCE_ID']
+#	    end
+#	  end
+#	end
+#      end
       response.to_ajp_response(ajp_req.output_cookies)
     rescue Object => exception
       puts exception.message + ":" + exception.backtrace.join("\n")

最後のパッチはどうしても下の状況が解決できなかったので無理やり。mod_jk初めてなので何がどういかんのかがわかりませんでした。orz

C:\home\kog\prj\todo>ajp-rails -c config/ajp.yaml
processing /ajp-mounted/task
can't convert nil into String:c:/ruby/lib/ruby/gems/1.8/gems/ajp-rails-0.1.0/lib
/ajp-rails/ajp_rails_dispatcher.rb:25:in `<<'
c:/ruby/lib/ruby/gems/1.8/gems/ajp-rails-0.1.0/lib/ajp-rails/ajp_rails_dispatche
r.rb:25:in `dispatch'
c:/ruby/lib/ruby/gems/1.8/gems/ajp-rails-0.1.0/lib/ajp-rails/ajp_rails_dispatche
r.rb:24:in `dispatch'
c:/ruby/lib/ruby/gems/1.8/gems/ajp-rails-0.1.0/lib/ajp-rails/ajp_rails_dispatche
r.rb:18:in `dispatch'
c:/ruby/lib/ruby/gems/1.8/gems/ajp-rails-0.1.0/lib/ajp-rails/rails-runner.rb:38:
in `process_request'
c:/ruby/lib/ruby/gems/1.8/gems/ruby-ajp-0.2.1/lib/net/ajp13/server.rb:171:in `pr
ocess_forward_request'
c:/ruby/lib/ruby/gems/1.8/gems/ruby-ajp-0.2.1/lib/net/ajp13/server.rb:145:in `pr
ocess'
c:/ruby/lib/ruby/gems/1.8/gems/ruby-ajp-0.2.1/lib/net/ajp13/server.rb:138:in `pr
ocess'
c:/ruby/lib/ruby/gems/1.8/gems/ruby-ajp-0.2.1/lib/net/ajp13/server.rb:103:in `st
art'
c:/ruby/lib/ruby/gems/1.8/gems/ruby-ajp-0.2.1/lib/net/ajp13/server.rb:100:in `st
art'
c:/ruby/lib/ruby/gems/1.8/gems/ajp-rails-0.1.0/lib/ajp-rails/rails-runner.rb:185

c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenci
es.rb:140:in `load'
c:/ruby/lib/ruby/gems/1.8/gems/ajp-rails-0.1.0/bin/ajp-rails:4
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenci
es.rb:140:in `load'
c:/ruby/bin/ajp-rails:18
processed /ajp-mounted/task: 200 OK

無理やりパッチしたところ、どうにかしたいなあ。

これで、fastcgi, scgi, ajpと3つ常駐させる技法が使えるようになった(と言い切れないか^^;)ので、かなり安心。特にajpについてはmod_jkのメンテナンスが期待できそうなので安心感がある。うまくやればIISとの連携でもいけるかもしれない。先にmod_rewriteをなんとかしなきゃなんないか。

あと、今回実験に使ったアプリがrailsのtrunkを参照してるので、rails1系でも試してみよう。