Jon A. Lambert
2006-Jan-06 08:11 UTC
[Rails] Routing problems - Apache proxy vs. Webrick direct
I dropped the use of fastcgi because I could not get popen working (see
''[Rails] Apache2 and popen''). It works under WebBrick. Since
CGI is too
slow, I thought I''d proxy to WebBrick via Apache.
I am having routing problems now with escaped slashes in the URL.
Here''s my routes.rb:
map.connect '''', :controller => "wiki"
map.connect '':controller/service.wsdl'', :action =>
''wsdl''
map.connect '':controller/:action/:id''
My request should drop down to the default action.
Here''s my apache vhost configuration:
# ProxyPass / http://localhost:3000/
# ProxyPassReverse / http://localhost:3000/
RewriteEngine On
ProxyPreserveHost On
RewriteRule ^/(.*) http://localhost:3000/$1 [P,L]
I''ve tried both above, what I have commented out and what I have
uncommented
with the same results below.
Here''s the url I request and the not found error in the apache logs:
10.0.0.2 - - [06/Jan/2006:02:49:19 -0500] "GET
/repository/index/lib%2Fnet%2F HTTP/1.1" 404 618
And here''s the error in my rails log:
Processing Base#index (for 127.0.0.1 at 2006-01-06 03:01:41) [GET]
Parameters: {}
ActionController::RoutingError (Recognition failed for
"/error/HTTP_NOT_FOUND.html.var"):
c:/apps/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:469:in
`recognition_failed''
c:/apps/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:459:in
`recognize!''
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
`dispatch''
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in
`handle_dispatch''
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in
`service''
c:/apps/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service''
c:/apps/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run''
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread''
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start''
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread''
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start''
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each''
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start''
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start''
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start''
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in
`dispatch''
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59
c:/apps/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require__''
c:/apps/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require''
c:/apps/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
`require''
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28
c:/apps/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require__''
c:/apps/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require''
c:/apps/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
`require''
c:/www/xxxxxxxxx/script/server:3
Rendering
c:/apps/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/templates/rescues/layout.rhtml
(404 Page Not Found)
It looks like all the params are empty????
Accessing the same URL, except bypassing Apache and using the Webrick port I
get success:
Processing RepositoryController#index (for 10.0.0.2 at 2006-01-06 03:04:26)
[GET]
Parameters: {"action"=>"index",
"id"=>"lib/net/",
"controller"=>"repository"}
Rendering within layouts/repository
Rendering repository/index
Completed in 0.63100 (1 reqs/sec) | Rendering: 0.03000 (4%) | DB: 0.03000
(4%) | 200 OK [http://xxxxxxxxxxxxxxxxxxxx/repository/index/lib%2Fnet%2F]
How do I fix this?
Thanks
J. Lambert
Bragi Ragnarson
2006-Jan-06 08:59 UTC
[Rails] Routing problems - Apache proxy vs. Webrick direct
Hi Jon, I am not very familiar with mod_rewrite but maybe adding QSA to the rule will help?> RewriteEngine On > ProxyPreserveHost On > RewriteRule ^/(.*) http://localhost:3000/$1 [P,L]RewriteRule ^/(.*) http://localhost:3000/$1 [QSA, P,L] As a side note: I have found lighttpd faster and more reliable than webrick for development. And I am using proxying Apache -> Lightttpd setup on my Textdrive account - it works like a charm. -- Bragi Ragnarson
Jon A. Lambert
2006-Jan-06 09:38 UTC
[Rails] Routing problems - Apache proxy vs. Webrick direct
Bragi Ragnarson wrote:> > RewriteRule ^/(.*) http://localhost:3000/$1 [QSA, P,L] >Thanks. I gave that a shot but I still get the same errors. -- J. Lambert
Jon A. Lambert
2006-Jan-06 09:46 UTC
[Rails] Routing problems - Apache proxy vs. Webrick direct
Jon A. Lambert wrote:> Bragi Ragnarson wrote: >> >> RewriteRule ^/(.*) http://localhost:3000/$1 [QSA, P,L] >> > > Thanks. I gave that a shot but I still get the same errors.I should add that I am having no trouble at all with other controllers in this same application using the Apache proxy to webbrick. The main difference with this particular controller is the escaping of /''s in the :id part. /repository/index/lib%2Fnet%2F -- J. Lambert
Jon A. Lambert
2006-Jan-06 10:21 UTC
[Rails] Routing problems - Apache proxy vs. Webrick direct
Jon A. Lambert wrote:> Jon A. Lambert wrote: >> Bragi Ragnarson wrote: >>> >>> RewriteRule ^/(.*) http://localhost:3000/$1 [QSA, P,L] >>> >> >> Thanks. I gave that a shot but I still get the same errors. > > I should add that I am having no trouble at all with other > controllers in this same application using the Apache proxy to > webbrick. > The main difference with this particular controller is the escaping > of /''s in the :id part. > > /repository/index/lib%2Fnet%2FLooks like it''s a mod_rewrite bug. http://issues.apache.org/bugzilla/show_bug.cgi?id=34602 And it''s also a Proxypass bug http://issues.apache.org/bugzilla/show_bug.cgi?id=29554 It''s only been broken for a year and a half. I guess I have to reevaluate how to do this. I''d like to pass a path to :id. Maybe use separators that won''t be stepped on by apache? -- J. Lambert
Jon A. Lambert
2006-Jan-06 12:15 UTC
[Rails] SOLUTION: Routing problems - Apache proxy vs. Webrick direct
Jon A. Lambert wrote:> > Looks like it''s a mod_rewrite bug. > http://issues.apache.org/bugzilla/show_bug.cgi?id=34602 > > And it''s also a Proxypass bug > http://issues.apache.org/bugzilla/show_bug.cgi?id=29554 > > It''s only been broken for a year and a half. > > I guess I have to reevaluate how to do this. > > I''d like to pass a path to :id. Maybe use separators that won''t be > stepped on by > apache?I thought I post my solution in case anyone else encounters this. I rewrote application. In routes.rb.. map.connect '''', :controller => "wiki" map.connect ''repository/index/*path'', :controller => "repository", :action => "index" map.connect ''repository/show/*path'', :controller => "repository", :action => "show" map.connect '':controller/service.wsdl'', :action => ''wsdl'' map.connect '':controller/:action/:id'' I pass the rest of the parms in an array. Can''t use *id for some reason above. Looks like this when the controller gets it. Parameters: {"action"=>"index", "controller"=>"repository", "path"=>["lib", "net"]} Also in my views, I couldn''t stuff the path into :id nor :path and use link_to. I expect :path gets walked on by the routing code above. So I had to create me own links. <%= "<a href=\"/repository/index/#{@fpath.empty? ? "": @fpath+''/''}#{f[0...-1]}\">#{f}</a>" %> -- J. Lambert