Configuring Tomcat5 and Apache2 with Virtual Hosts using mod_jk - Page 4
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.
- 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.
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.
- 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.
- Finally test the websites by entering the respective url into your browser:
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.
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.