Forum: Ruby on Rails multiple virtual host?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (dankelley)
on 2007-04-02 17:39
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
    ProxyPassReverse  /APP
    ProxyPass /images
<VirtualHost *:80>
    ServerName URL
    ServerAlias URL
    ServerAdmin USER@PLACE
    ProxyPass /NEWAPP
    ProxyPassReverse  /NEWAPP
    ProxyPass /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 -e development --prefix /APP
mongrel_rails start -d -p 8010 -a -e development --prefix

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?
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-04-02 20:56
(Received via mailing list)
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.

94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (dankelley)
on 2007-04-03 01:26
Interesting.  But the URL ("", 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

for APP, and


(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.

8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-04-03 01:51
(Received via mailing list)
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

94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (dankelley)
on 2007-04-03 02:03
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
7c8f8b6eae4dd991e3a9065c68451361?d=identicon&s=25 Wai Tsang (sneptune)
on 2007-04-03 03:03
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 and 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.
94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (dankelley)
on 2007-04-03 15:00
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.
7c8f8b6eae4dd991e3a9065c68451361?d=identicon&s=25 Wai Tsang (sneptune)
on 2007-04-03 15:22
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.
D220ebc8759a44868c189856aebe47a0?d=identicon&s=25 (Guest)
on 2007-04-03 21:21
(Received via mailing list)
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 and 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 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 <Location> directive
*within* your VirtualHost directive that set up the proxy settings you
wish to use for each location.  Have a look at for more
information (assuming Apache 2.2...similar sections are available for
other version of the Apache server/documentation).

Best of luck!


On Apr 3, 9:00 am, Dan Kelley <>
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-04-03 22:48
(Received via mailing list)
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

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.


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.
94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (dankelley)
on 2007-04-03 23:40
> If you want to do path based
> determination of settings you need to use a <Location> 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

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.
This topic is locked and can not be replied to.