[LRUG] [OT:Apache] Mapping multiple domains to different controllers?

Johnathan Loggie me at johnno.com
Tue Apr 14 03:32:49 PDT 2009


You are on the right track with what you're trying, but you need to decide
if your second vhost is going to be [1] proxying to the other vhost or [2]
serving your rails app through passenger, and what you have there in your
example is halfway between the two.

[1] If you want to use mod proxy then your second vhost should not be
passenger enabled, otherwise this might hinder the use of other modules such
as the proxing, if you think about it why would you want a vhost that was
both a rails app and a proxy at the same time. So have PassengerEnabled off
and then try the proxying.

[2] It would make more sense to try to avoid proxying to yourself, as this
may occur a performance hit. So rewriting the url before the request hits
passenger may be better.

So start with both Vhosts the same, using passenger and the document root
the same. So your only problem would be that somethingelse.com would be
serving the wrong part of your app, so you want to kind of push the requests
deeper into the app if you like.  So your idea about using ModAlias makes
sense, as an alias is in effect what you want, but this may not work with
passenger as I think mod alias really just works by modifying file paths so
works for things like static content or cgi scripts.

Using mod_rewrite you can rewrite the URL which should occur before
passenger sees it, so that by the time passenger sees the URL it will be
correct for your routes to give the correct controller.

You don't want the [P] option as you are not proxying, only rewriting.
The [PT] option might be needed but I doubt it.

PassengerHighPerformance off
RewriteEngine on
RewriteRule ^(.*)\/?$ http://myapp/$1

So, keep trying but don't try to do two things at the same time, either
proxy from one vhost to the other, or use rewriting/aliasing to change the
url before passenger sees it.


Johnno

On 14/04/2009 00:50, "Matthew Rudy Jacobs" <matthewrudyjacobs at gmail.com>
wrote:

> Hey,
> I know this isn't ruby,
> but I can't work this out.
> 
> It's kind of the opposite to the old "http://mydomain/app1" and
> "http://mydomain/app2" pointing to two different applications.
> 
> What I want is "http://domain1" and "http://domain2"  to point to the
> same rails app, but transparently rewritten to /domain1 and /domain2
> 
> And I was hoping there might be an apache guru looking for a way of
> wasting time.
> 
> Boiling it down;
> 
> I have an app that lives at; ~/myapp
> it has a public directory at: ~/myapp/public
> 
> This runs happily on MyDomain.com
> 
> I have a controller OtherDomainController
> with the path /other_domain
> and the static directory ~/myapp/public/other_domain
> 
> I want to setup a VHost for SomethingElse.com,
> so that;
> 
> 1. A request to "http://SomethingElse.com" should return the same
> content as one to "http://MyDomain.com/other_domain"
> 2. It should achieve this without redirecting
> 3. It should serve ~/myapp/public/other_domain/index.htm to requests
> for "http://SomethingElse.com/" if it is present
> 
> I have a gist - http://gist.github.com/94828
> with a couple of things I've tried...
> 
> but I'm stumped.
> 
> Doing a normal redirect is fine,
> but I don't want to issue a 302, I just want apache to deal with the
> redirect internally (and [P] seems to break)
> and I can't seem to make ModProxy work for me.
> 
> Any ideas as to where I'm going wrong?
> Maybe its ModAlias I should be using.
> 
> I've thought of ways of doing it with a rack pre-processor,
> but surely apache eats this stuff for brunch?
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> 





More information about the Chat mailing list