How To Install Tomcat6 With SUN-Java And Apache2 Integration On Ubuntu 10.04 [Lucid Lynx] With Virtual Hosts - Page 2

4.3 Setup a new virtual host in Apache2

Create the folders for our new virtual host:

mkdir /var/www/
mkdir /var/www/
mkdir /var/www/

Then create a new site in Apache2:

vi /etc/apache2/sites-available/

Then add:

<VirtualHost *:80>
    JkMount /* default
    ServerAdmin [email protected]
    DocumentRoot /var/www/
    ErrorLog /var/www/
    CustomLog /var/www/ combined
    <Directory /var/www/>
        Options -Indexes

Note: JkMount can be setup in different ways.

JkMount /* will use tomcat for all files
JkMount /*.jsp only for .jsp files
JkMount /folder/* for tomcat files in a specific directory

Enable the new virtual host we created, by running:



4.4 Setup a the new virtual host in Tomcat6

Open up the configuration file for Tomcat6:

vi /etc/tomcat6/server.xml

Find the following lines:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

And uncomment the connector port, like this:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Then scroll down and find:


AFTER the ending </Host> tag, and BEFORE the ending </Engine> tag, insert the following:

<!-- -->
<Host name="" appBase="/var/www/" unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="htdocs" debug="0" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/www/"  prefix="tomcat_access_" suffix=".log" pattern="common" resolveHosts="false"/>

Make sure you replace with your details in all the places.

Now lets create a Catalina folder for our new domain:

mkdir /etc/tomcat6/Catalina/

And copy the original context files to new domain:

cp /etc/tomcat6/Catalina/localhost/* /etc/tomcat6/Catalina/

But remove the ROOT.xml file, because we don't need that one on our new domain:

rm -f /etc/tomcat6/Catalina/


4.5 Create a test file and test our new setup

Create a new test.jsp file for our new virtual host:

vi /var/www/

and add:

        <title>Hello World</title>
        <h1>Hello World</h1>
        Today is: <%= new java.util.Date().toString() %>

Save and exit the file.

Finally restart the services, so that the new configuration will load:

/etc/init.d/apache2 stop
/etc/init.d/tomcat6 restart
/etc/init.d/apache2 start

Then use your browser to visit and verify that you get the test page we just created.

You should also be able to visit which is now also available on our virtual host (/docs, /manager/html and /host-manager/html should also work):

Your done!





Apache2 configuration


Tomca6 configuration


Restart Apache2 and Tomcat6

/etc/init.d/apache2 stop
/etc/init.d/tomcat6 restart
/etc/init.d/apache2 start
Share this page:

5 Comment(s)