Configure several Apache servers on multiple VMs


This article is the third one in a serie about configuring several web server on multiple virtual machines inside a single physical host. VirtualBox is supposed to be installed and the VMs have been created, we can now get to the Apache configuration on the guests and the host.

The choice of the architecture has been made that way : the VMs won’t be visible from internet. An Apache front-end on the guest is setup as a reverse-proxy and redirects the incoming requests to the right server depending of the requested domain. DNS entries of the managed domains are configured to point on the physical machine IP.

The VMs will then have access to 2 different network interfaces :

Interface 1 : NAT network access : useful to have a direct access to the net from the machines (for package update and so on…).

Interface 2 : “Host-only adapter”, which allows to make a private network between the guests and the host.

Step 1 : private network configuration

In the administration tool, get to File>Preferences…, then in the tab Network and click on “Add host-only network“.

Then click “Edit host-only network“, go to “DHCP Server” tab, and check that the DHCP server is activated. The VMs will receive a (temporary) IP adress as soons as they start.

Step 2 : Associate a new interface to the VMs

Before that, go to File…/Preferences…/Network, and create a new private network name.
Then, you can select each virtual machine, do a shutdown, then go to “network setup” and add an interface 2 with a host-only network.

Then connect to the machines (with the temporary IP adress or via any RDP tool) and configure the system to use this new interface. For instance, on a Debian/Ubuntu VM, the following lines must be added in the /etc/network/interfaces file :

After rebooting, the virtual machine will be connected to the network, and can be seen from the host :

ifconfig from host server ifconfig from a VM

Step3 : Configure a NAT port forwarding

This is optional but handy if you need to test the VMs services. This step associates a TCP port for every VM’s service. For instance, the 8001 port can be chosen to be linked to the 80 port (apache) of the first VM. (you can do the same to ssh services to connect easily on the guest servers)
This step can be achieved online (on running virtual machines).

Step 4 : Apache configuration on the host

Apache will be setup as reverse proxy. To start, the following apache modules must be enabled :

Then you must write a configuration file for each host, for instance :

Of course, you must change you domain name and IP adress with yours.

Giving the website’s adress to this file is a good idea, as it makes enabling or disabling it very easy.

Enable the site, and reload apache


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Crocoware technical blog