Configuring Tomcat5 and Apache2 with Virtual Hosts using mod_jk - Page 4
Configure Apache
Important note: Be sure to make a copy of your config files before modifying.
- Open your Apache2 configuration file and add the following just below the line Include /usr/lib/apache-tomcat/conf/auto/mod_jk.conf.
# Where to find workers.properties |
- This next section assumes you are using virtual hosts. In this system I am running ISPConfig where all of my Vhosts are defined in a separate file.
Otherwise, if you are not using ISPConfig and your Vhosts are defined within your main Apache2 config file, you just need to add this code there within the desired Vhosts that you want to utilize Tomcat (JSP/Servlets).
If you are not running Vhosts, simply add this code at the bottom of your main Apache2 config file.
For those running ISPConfig as I am, you will need to either manually place this code in the master Vhost (localhost) in the /etc/apache2/vhosts/Vhosts_ispconfig.conf or the selected Vhosts that you want to utilize Tomcat (JSP/Servlets) using the ISPConfig control panel—in the Apache Directives window for each website.
This is up to you.
For this server, I have the ISPConfig Vhosts defined in /etc/apache2/vhosts/Vhosts_ispconfig.conf.
You can either place this code after the <VirtualHost ipaddress:port> tag or just before the </VirtualHost> end tag. ISPConfig documentation recommends that you use the control panel to include any additional virtual host directives.
# Send servlet for context /servlets-examples to worker named worker1 |
Conclusion
To finalize and test this configuration you will need to copy the Tomcat example JSP files to the virtual host web directory that was defined in the server.xml, apache2.conf, and Vhosts_ispconfig.conf files. In the server.xml file you will notice that I am referencing the jsp-examples directory where jsp-examples is the name of the docbase. This will give you some idea of how the web applications will be setup for your website. You can find more details on the Tomcat website on how to generate your original web applications. In order to define another web application, you would need to define another worker (i.e. worker2) in the workers.properties file, add another host in the server.xml file, and add the same directives (using worker2 of course) to the respective VHost section.
<!-- www.domain1.org --> |
- First copy just the jsp-examples directory to web1.
cp -R /usr/lib/apache-tomcat/webapps/jsp-examples /home/www/web1/web |
- Next you need to restart Tomcat as described earlier and then restart Apache. Remember to restart Tomcat first so you will regenerate the mod_jk.conf file.
cd /usr/lib/apache-tomcat/bin sh shutdown.sh sh startup.sh /etc/init.d/apache2 restart |
- Finally test the websites by entering the respective url into your browser:
http://www.domain1.org/jsp-examples/ |
You should see the same jsp-examples html as you did in the default Tomcat page from earlier.
Congratulations! Your server should now be ready to support JSP/Servlets. Again, if you find any inconsistencies within this tutorial, please contact me so I can make the appropriate corrections.
Resources/Links
This tutorial was compiled using several resources that I found on the internet. Due to the trouble I had finding all of this information it only made sense to put it all together.
http://blog.gilluminate.com/?s=10
Integrating Tomcat and Apache on Red Hat Linux
http://tomcat.apache.org/connectors-doc-archive/jk2/jk2/vhosthowto.html
http://tomcat.apache.org/connectors-doc/howto/apache.html
The Perfect Setup - Debian Sarge (3.1)
http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/source/jk-1.2.15/