Multiple virtual host?

I am trying to serve up two applications from one box. (It’s not a
commercial system; it’s just a box on my desktop, that I’m using to test
out RoR.)

SETUP. In my httpd.conf, I’ve got something like

<VirtualHost *:80>
ServerName URL
ServerAlias URL
ServerAdmin USER@PLACE
ProxyPass /APP http://127.0.0.1:8000/APP
ProxyPassReverse /APP http://127.0.0.1:8000/APP
ProxyPass /images http://127.0.0.1:8000/APP/images

<VirtualHost *:80>
ServerName URL
ServerAlias URL
ServerAdmin USER@PLACE
ProxyPass /NEWAPP http://127.0.0.1:8010/NEWAPP
ProxyPassReverse /NEWAPP http://127.0.0.1:8010/NEWAPP
ProxyPass /images http://127.0.0.1:8010/NEWAPP/images

where URL is for my machine, and APP and NEWAPP are the names of two
applications, which I serve up with

mongrel_rails start -d -p 8000 -a 127.0.0.1 -e development --prefix /APP
mongrel_rails start -d -p 8010 -a 127.0.0.1 -e development --prefix
/NEWAPP

THE PROBLEM. Only one site works. (The problem is in the setup, not
the site code, because I can make either one work by commenting out
parts of my httpd.conf file.)

Q: how should I set up httpd.conf (or mongrel_rails) to serve two
applications from one box?

The ServerName (and ServerAlias) need to be different for the two
different virtual hosts. It’s not enough to just proxy them to different
internal URLs.

b

Interesting. But the URL (“my.computer.com”, in the examples below) is
determined by my system adminstrator and someone who set up a DNS table,
isn’t it? I’m confused; the examples I’ve seen suggest that I can just
invent new URLs, but I don’t see how that can work.

Or is the idea to put something after the “/” in a URL, e.g. to name the
two sites

my.computer.com/a/APP

for APP, and

my.computer.com/b/NEWAPP

for NEWAPP?

(And, should I therefore be calling mongrel_rails differently?)

I’m sorry I’m being so dense on this. I’m only following up, continuing
to be a pest, because I think others might be interested.

D

Given this, I wonder how one can host more than one RoR site on a given
box, without changing any DNS tables on a higher-up box.

At least from my limited academic perspective, this is an important
facet of a web scheme. I have many little websites on my box, e.g. one
for each course I teach, one for each multi-author paper I write, one
for each multi-PI proposal I write, etc. (I wonder whether the web
would have spread, in its early academic days, if things weren’t so
easy.)

If you don’t want to get another domain name, you may ask other people
to update their hosts file (/etc/hosts), or you may serve each websites
on different port.

The idea of virtual host is that requests are forwarded according to the
domain name of the request. So that www.abc.com and www.def.com will be
served differently even though the ip address is the same.

Alternatively, you may obtain multiple IP addresses and bind each site
to it if you are only serving in local area network.

My summary so far, for anyone catching this thread with a search:

PHP: users with no special privileges can create dozens of sites using
the (HOST)/~(USER)/(SITENAME) scheme. This is done without restarting
the web server, and without editing (and thus potentially damaging)
configuration files.

RoR: some special magic is required. (I’m not sure what, yet.)

Thus PHP is analagous to HTML, in the sense that ease of use is likely
to create a wide community of experts. I hope that RoR (and Django and
the like) can build up such a community somehow.

Hi Dan,

I believe you have got the wrong idea about virtual host, virtual host
is for domain name mapping, not subdirectory. You can do this in rail
with by updating the route.rb to override the default routing rule, or
with restful. I believe restful is the way to go for the
(HOST)/~(USER)/(SITE) scenario.

You can also create a controller for each user if each user request is
handled differently.

You can’t just make up URLs and expect them to work on the open web…
that’s what DNS is for.

For using strictly on your local machine, you can make up host names and
put them in your hosts file (/etc/hosts on *nix, google for it on
windows).

b

I don’t think this has anything to do with Rails. You would have the
same problem if you were using PHP. This boils down to a mis-
understanding of the purpose of the VirtualHost directive in Apache.
The way virtual hosts work is to match against the Host header in the
HTTP request (basically the client connects to the server using the
server’s IP but also provides the hostname it was initially asked to
connect to). So if i set up my DNS zones so that www.blah.com and
www2.blah.com both resolve to the same IP my browser will provide
which of the 2 I asked for to the server when connecting. Apache then
uses this information to determine which VirtualHost directive to use
to process the request. The path that is being requested (the /
blah.html in www.blah.com/blah.html) is part of the actual request,
not the HTTP headers and thus not available to Apache at the time when
it needs to make its vhost decision. If you want to do path based
determination of settings you need to use a directive
within your VirtualHost directive that set up the proxy settings you
wish to use for each location. Have a look at
core - Apache HTTP Server Version 2.2 for more
information (assuming Apache 2.2…similar sections are available for
other version of the Apache server/documentation).

Best of luck!

~Ross

On Apr 3, 9:00 am, Dan K. [email protected]

The only reason “(HOST)/~(USER)/(SITENAME)” works for you is because the
sysadmin of your server configured apache to map ~username to a
directory in your home directory. The php then works in this scenario
because it is just template files, html with php code which mod_php runs
and replaces.

Rails does not work on this principle. It is for building complete,
well-architected web applications. The template files (the html with
ruby embedded) are not publicly accessible because Rails processes the
file for us and writes the final output into the http socket output
stream.

That probably sounds overly academic, but there are very good reasons
why it is designed that way. Basically, if you just want to embed some
code into an html file, stick with php.

b

PS: Oh, with correct configuration of apache, you can use the ~user
stuff with rails as well. However, you’d need edit access to the apache
config and you’d need to know what you are doing.

If you want to do path based
determination of settings you need to use a directive
within your VirtualHost directive

Thanks, Ross, I’ll check into that.

I’ve been trying to deploy my app for months now. (A search on this
forum would illustrate the kindness of strangers who have helped me in
this, and my very slow understanding of the advice offered.) Luckily,
my app is mainly an experiment to see whether RoR will prove useful for
me, so I have the luxury of revisiting the problem in the evenings or on
weekends.

I’ve found that the ratio of (effort in learning RoR) to (effort in
deploying RoR) to be unexpectedly high. It’s a bit of a shame that this
ratio is so seldom mentioned in the tutorials that (reasonably) sing the
praises of RoR.

Oh well, I enjoyed reading the Agile book on RoR, so I guess I’ll buy
the book on deploying RoR as well … even though, in the end, I expect
I’ll just be copying ten lines from the book into my httpd.conf file.