Subject:      howto/multiple-servers.txt

Several people have expressed an interest in having multiple servers
running on the same machine serving different information for different
hostnames.  The following information explains some of the issues involved
and how to do it (which is now easy because the server supports it).

Say I want http://WWW.BSDI.COM and http://WWW.JOE.NET to be different WWW
servers running on the *same* physical machine and both on port 80.  Now,
you could just put all the data in one place and use simple path names to
differentiate between them:
    http://www.bsdi.com/bsdi/index.html
    http://www.joe.net/joe/index.html
But this is unpleasent and we can't have that.  We want to be able to say:
    http://www.bsdi.com/
and get the "right" server.

A solution:

Since the protocol cannot differentiate on the logical name you will need
to be able to assign multiple IP addresses to the machine to get this to
work (if you have multiple interfaces on the machine you are all set).
*HOWEVER*, if your DNS server is setup to rotary those IP addresses you
will have to be careful.  There isn't currently a way to bind a single
running server to a set of addresses so this only works if DNS always
returns the same answer (unless you want to run a server per IP Address,
which you can do if you want).  You should also consider the implication
of running one server on INADDR_ANY (that's the default and handles
all incoming requests for your machine, no matter what the IP address).
If you have one server bound to 137.39.95.2,80 and another bound to
0.0.0.0,80 then things will work as you expect until the server on
137.39.95.2,80 goes down, and then the 0.0.0.0,80 server will start
answering requests for 137.39.95.2,80!!!  So long as you understand
how this works this could be a big *feature*; you could setup a simple
server bound to 0.0.0.0,80 that just says,
    "sorry, temporarily out of service"
so that whenever your main server is down it catches it (and maybe
even sends you email!!!).

On late-model BSD systems (including BSD/386, plug plug :-) you can use
the alias feature of ifconfig to add another IP address to an existing
interface:
    ifconfig ef0 inet 192.124.139.2             # configure interface
    ifconfig ef0 192.124.139.100 alias          # add an alias

When running multiple servers from the same source don't forget
to set [-P pidfile].  You'll also probably want to use different
configuration files and [-d topdir]'s.

To bind plexus to a specific address, simply use the -h option:
	plexus -h austin.bsdi.com

That's it!  Now you have a different server bound on that IP address,
sharing port 80 [the more "specific" address binds more tightly so
137.39.95.2,80 will beat out 0.0.0.0,80].

Here is a more complete example of running two servers on one machine from
a shared server tree:
    /usr/local/www/server/austin.conf:
	require "$plexus_src/plexus.conf";
	$hostname          	= "austin.bsdi.com";
	$http_localcfg		= "austin-local.conf";
    /usr/local/www/server/austin-local.conf:
	[put your copy of local.conf here]

    /usr/local/www/server/earth.conf:
	require "$plexus_src/plexus.conf";
	$hostname          	= "earth.com";
	$http_localcfg		= "earth-local.conf";
    /usr/local/www/server/austin-local.conf:
	[put your copy of local.conf here]

Then start the servers like this:
    /usr/local/www/server/plexus -h austin.bsdi.com \
        -s /usr/local/www/server -c austin.conf -d /usr/local/www  
    /usr/local/www/server/plexus -h earth.com \
	-s /usr/local/www/server -c earth.conf -d /usr/local/earth  

This exports /usr/local/www on austin.bsdi.com and /usr/local/earth on
earth.com; both using the code from /usr/local/www/server.
