I''m trying to make Mongrel the default web server for Typo, but I''m running into a problem. Is there an easy way to run a Rails app in a subdirectory ( http://foo/blog instead of http://foo/) with Mongrel? For most apps, I''d just change routes.rb to include the prefix that I wanted, but that won''t really work with Typo--I''d rather not require a few hundred users to modify Typo''s source code if I can avoid it. I''d rather handle this via Mongrel. I tried changing the ''uri "/", :handler => rails(:mime => mime)'' line in mongrel_rails (both directly and via a -S config script) and that doesn''t quite do the job--the Rails app still thinks it''s running in ''/'', so routes are broken. Is there an easy way to handle this? If not, would a patch that adds a --prefix command-line flag for mongrel_rails (along with a few lines of plumbing) be accepted? Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060710/fe23e39e/attachment.html
Rails apps like to run absolutely on root, and mongrel follows that. The default mongrel application is built as an application server serving one rails application sitting on its own root, viz: http://127.0.0.1/controller/action To handle anything else you need to rewrite the path so that it proxies to root. This appears to be a rails restriction rather than mongrel. So http://some.web.address/app1/controller/action gets mapped by a web server to http://app1.mongrel.ip.address/controller/action The only way to get more than one rails application running under a single web address is to use proxy mappings and URL rewrites through some tool that does that (Apache, lighttpd, pound, etc). -- NeilW -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060710/7426e42f/attachment-0001.html
Er, okay. The thing is, this is *trivial* with Apache and fcgi--just add ''RewriteBase /blog/'' to your usual rewrite config and it Just Works. Routes work correctly in both directions. A lot of users are using this with Typo. Until we added it to our default config (commented out), it was probably our #1 support question. I''ve already started getting "how do I do this with Mongrel" questions. Now, it''s certainly possible to edit routes.rb and prefix everything with ''/blog/''. I could move the static stylesheets and images in public/ around, too. But that''s kind of a pain when we''re dealing with thousands of users, quite a few of whom have never dealt with Rails before. I''d really like a solution that is http proxy-agnostic--it doesn''t matter if they''re using Apache, Lighttpd, Lightspeed, or whatever. I''d love the directions to say "just proxy /(base) through to http://backend:port/(base)". I''ll spend a couple hours trying to wrap my head around Rails''s dispatch process, Mongrel, and mod_rewrite and see if I can figure out what I need to hand to Rails to make this work right. Scott On 7/10/06, Neil Wilson <aldursys at gmail.com> wrote:> > Rails apps like to run absolutely on root, and mongrel follows that. > > The default mongrel application is built as an application server serving > one rails application sitting on its own root, viz: > > http://127.0.0.1/controller/action > > To handle anything else you need to rewrite the path so that it proxies to > root. This appears to be a rails restriction rather than mongrel. > > So > > http://some.web.address/app1/controller/action > > gets mapped by a web server to > > http://app1.mongrel.ip.address/controller/action > > The only way to get more than one rails application running under a single > web address is to use proxy mappings and URL rewrites through some tool that > does that (Apache, lighttpd, pound, etc). > > -- > NeilW > > > > > > > > > > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060710/0a692723/attachment.html
-----Original Message----- From: mongrel-users-bounces at rubyforge.org [mailto:mongrel-users-bounces at rubyforge.org]On Behalf Of Scott Laird Sent: 10 July 2006 21:42 To: mongrel-users at rubyforge.org Subject: Re: [Mongrel] Rails app in a subdirectory via Mongrel Er, okay. The thing is, this is *trivial* with Apache and fcgi--just add ''RewriteBase /blog/'' to your usual rewrite config and it Just Works. Routes work correctly in both directions. So can you not do the same with the proxy? Mongrel is a replacement for FCGI, not the Apache/FCGI pair. If Rails knew which prefix it lived on and could generate all its refer and redirect URLs relative to that prefix rather than just root, then you wouldn''t need a rewriter proxy - Mongrel could just pass the URL in and out unadulterated. Should Rails know where it lives in the URL tree though? Is that the job of the application or the web server? Perhaps the solution to the ''loads of http proxy front ends'' is to consider that none of them are fit for *our* purposes - much as FCGI wasn''t fit for the application server purpose. Anybody got to the stage where that itch is worth scratching? NeilW -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060710/693bc815/attachment.html
This still doesn''t seem quite right--how does url_for work right if the back end doesn''t know where it actually lives? Does the proxy have to rewrite all HTML passing through it? I know that there''s a module for that for Apache (mod_proxy_html), but it requires a lot more work then normal proxying. It''d be a lot cleaner if we could generate the right HTML in the first place.>From http://dev.rubyonrails.org/ticket/2602, it looks likerequest.relative_url_root is the method that I was looking for inside of Rails. It has special-case support for Apache--it spots dispatch.fcgi in the request path and calculates the correct root on its own. I''ll take a look at patching mongrel_rails to add a --prefix flag and then pass the path onto the Mongrel::Rails. Scott On 7/10/06, Neil Wilson <aldursys at gmail.com> wrote:> -----Original Message----- > From: mongrel-users-bounces at rubyforge.org [mailto:mongrel-users-bounces at rubyforge.org]On Behalf Of Scott Laird > Sent: 10 July 2006 21:42 > To: mongrel-users at rubyforge.org > Subject: Re: [Mongrel] Rails app in a subdirectory via Mongrel > > > Er, okay. The thing is, this is *trivial* with Apache and fcgi--just add ''RewriteBase /blog/'' to your usual rewrite config and it Just Works. Routes work correctly in both directions. > > > > So can you not do the same with the proxy? Mongrel is a replacement for FCGI, not the Apache/FCGI pair. > > If Rails knew which prefix it lived on and could generate all its refer and redirect URLs relative to that prefix rather than just root, then you wouldn''t need a rewriter proxy - Mongrel could just pass the URL in and out unadulterated. Should Rails know where it lives in the URL tree though? Is that the job of the application or the web server? > > Perhaps the solution to the ''loads of http proxy front ends'' is to consider that none of them are fit for *our* purposes - much as FCGI wasn''t fit for the application server purpose. Anybody got to the stage where that itch is worth scratching? > > NeilW > > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users > >
On Mon, 2006-07-10 at 12:38 -0700, Scott Laird wrote:> I''m trying to make Mongrel the default web server for Typo, but I''m > running into a problem. Is there an easy way to run a Rails app in a > subdirectory (http://foo/blog instead of http://foo/) with Mongrel? > For most apps, I''d just change routes.rb to include the prefix that I > wanted, but that won''t really work with Typo--I''d rather not require a > few hundred users to modify Typo''s source code if I can avoid it. I''d > rather handle this via Mongrel. >Nope, you need to have Rails handle it.> I tried changing the ''uri "/", :handler => rails(:mime => mime)'' line > in mongrel_rails (both directly and via a -S config script) and that > doesn''t quite do the job--the Rails app still thinks it''s running in > ''/'', so routes are broken. Is there an easy way to handle this? >Nope that won''t work since the HTML that rails generates would then have all the wrong URIs. You''d request /myappliveshere/users/dostuff, and then all the links, redirects, everything would point to /users/dostuff. You have to tell rails that it lives at /myappliveshere. I could swear that there was a config option you can put in your environment.rb which tells Rails it''s at a different base URI.> If not, would a patch that adds a --prefix command-line flag for > mongrel_rails (along with a few lines of plumbing) be accepted?Mongrel *can not* help you with this. The problem is that in order for you to put an app at a different URI base the app needs to rewrite all URIs to include this base. If you don''t get rails to do it then the web server has to do it and I flat out refuse to troll through html changing links. :-) I imagine previously that''s what your apache config with fastcgi was doing. There just isn''t any other way to do it outside of rails. This also means that your previous config was horribly inefficient. Snoop around on the interwebs and google for this magic config. I''m pretty sure I''m not crazy, but it''s something like: config.action_controller.rails_root = "/myappliveshere" Or maybe it was a routes.rb setting. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?
On 7/10/06, Zed Shaw <zedshaw at zedshaw.com> wrote:> > > I imagine previously that''s what your apache config with fastcgi was > doing. There just isn''t any other way to do it outside of rails. This > also means that your previous config was horribly inefficient. > > Snoop around on the interwebs and google for this magic config. I''m > pretty sure I''m not crazy, but it''s something like:ActionController::AbstractRequest.relative_url_root = "/myappliveshere". Amazingly enough, it''s special-cased for Apache with FastCGI--if it spots dispatch.[f]cgi in the right environment variable, then it sets relative_url_root automatically. That''s why it works with Apache most of the time :-). That''s the magic I was missing this morning. So, if you add relative_url_root to environment.rb (or $RELATIVE_URL_ROOT to the environment) to ''/blog'', then you can proxy from http://real-server:80/blog to http://localhost:4123/ (running Mongrel) and all of the generated URLs work. But, you won''t be able to access the backend directly for debugging, because it''ll be expecting urls that start at / and generating urls that start with /blog/. I have a little patch that adds a --prefix flag to Mongrel that sets the Rails handler URI as well as relative_url_root. As I mentioned above, it''s not strictly needed, but it''ll make life a bit easier for people. Would this be something that you''d be interested in applying, or should I go tweak the Typo docs to explain it away? Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060710/5deade88/attachment.html
On Mon, 2006-07-10 at 16:11 -0700, Scott Laird wrote:> > > On 7/10/06, Zed Shaw <zedshaw at zedshaw.com> wrote: > > ActionController::AbstractRequest.relative_url_root > "/myappliveshere". Amazingly enough, it''s special-cased for Apache > with FastCGI--if it spots dispatch.[f]cgi in the right environment > variable, then it sets relative_url_root automatically. That''s why it > works with Apache most of the time :-). That''s the magic I was > missing this morning.That''s it! But, uh that''s retarded that it only works with fcgi. I''ll talk to rails core and have them shore this up for the next release since they''re going Mongrel with it.> I have a little patch that adds a --prefix flag to Mongrel that sets > the Rails handler URI as well as relative_url_root. As I mentioned > above, it''s not strictly needed, but it''ll make life a bit easier for > people. Would this be something that you''d be interested in applying, > or should I go tweak the Typo docs to explain it away?Sure, shoot me the patch offline and I''ll look at how to work it in. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?