Linux Working with Multiple Names and Services

From National Gallery Research Wiki
Jump to navigation Jump to search

When working with complicate website set-ups or dealing with more than one web-server; Apache, Tomcat, D2R, etc it may be useful to have more than one web address pointing to different parts of a single machine and/or redirects from the standard port 80 to other ports. Below is a set of instructions that could be used to prepare a single machine for this kind of complex set-up

This page is part of the Linux Setup discussion.


The set of instructions assumes you have already followed the General and Apache set-up steps and installed a Tomcat server.


This page will describe the basic process for setting up, under Ubuntu:

  1. Virtual servers.
  2. Using multiple server names.
  3. Mapping server names to specific document roots.
  4. Using the libapache2-mod-jk to map a Tomcat server to a standard port 80 addresses.

There are a number of different web pages describing these processes, going into more detail about how they work. Just try Googling "Ubuntu Apache2 Tomcat6". This page is only a basic HowTo.


Install libapache2-mod-jk

sudo apt-get install libapache2-mod-jk

Edit the /etc/libapache2-mod-jk/ file

An edited example can be seen here:

sudo gedit /etc/libapache2-mod-jk/

Edit the /etc/apache2/httpd.conf file

sudo gedit /etc/apache2/httpd.conf
NameVirtualHost *:80

# Main web address and document root
<VirtualHost *:80>
ServerAlias Name1
DocumentRoot /var/www/

# Example redirect of Tomcat service1 through standard webaddress
JkMount /service1 worker2
JkMount /service1/* worker2

# Additional server name redirected straight to the Tomcat server
<VirtualHost *:80>
ServerAlias Name2

JkMount / worker1
JkMount /* worker1

# Secondary server name with separate document root
<VirtualHost *:80>
ServerAlias Name3
DocumentRoot /var/www2/projectname

Edit the /etc/apache2/mods-enabled/jk.load file

sudo gedit /etc/apache2/mods-enabled/jk.load

Edit the file to read:

LoadModule jk_module /usr/lib/apache2/modules/
JkWorkersFile /etc/libapache2-mod-jk/
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel error

Create any new Document Roots

For this example we would need:

sudo mkdir /var/www2
sudo mkdir /var/www2/projectname

adjust the permissions on the new document root if required.

sudo chmod -R a+w /var/www2

Restart Tomcat and Apache

sudo /etc/init.d/tomcat stop
sudo /etc/init.d/tomcat start
sudo /etc/init.d/apache2 restart


Hopefully your system should be up and running now ;-)