Linux Working with Multiple Names and Services

From National Gallery Research Wiki
Jump to: navigation, 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.

Preparation

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

Summary

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.

Process

Install libapache2-mod-jk

sudo apt-get install libapache2-mod-jk

Edit the /etc/libapache2-mod-jk/workers.properties file

An edited example can be seen here:

sudo gedit /etc/libapache2-mod-jk/workers.properties

Edit the /etc/apache2/httpd.conf file

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

# Main web address and document root
<VirtualHost *:80>
ServerName Name1.ng-london.org.uk
ServerAlias Name1
DocumentRoot /var/www/

# Example redirect of Tomcat service1 through standard webaddress
# Name1.ng-london.org.uk/service1
JkMount /service1 worker2
JkMount /service1/* worker2
</VirtualHost>

# Additional server name redirected straight to the Tomcat server
<VirtualHost *:80>
ServerName Name2.ng-london.org.uk
ServerAlias Name2

JkMount / worker1
JkMount /* worker1
</VirtualHost>

# Secondary server name with separate document root
<VirtualHost *:80>
ServerName Name3.ng-london.org.uk
ServerAlias Name3
DocumentRoot /var/www2/projectname
</VirtualHost>

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/mod_jk.so
JkWorkersFile /etc/libapache2-mod-jk/workers.properties
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

Complete

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