Friday, July 8, 2011

Integrate Apache and Tomcat

This integration is to provide more security on hosting.
  1. Install Apache2.2, Tomcat5.5 and libapache2-mod-jk 1:1.2.25-2
root # apt-get install apache2 tomcat5.5
root # apt-get install libapache2-mod-jk
  1. Enable jk module in apache if not enabled.
root # a2enmod jk
  1. Restart Apache
root # /etc/init.d/apache2 stop
root # /etc/init.d/apache2 start
  1. Create/Edit jk.conf file in /etc/apache2/mods-available to contain the following contents and create a soft link from apache2/mods-enabled
<IfModule mod_jk.c>
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkRequestLogFormat "%w %V %T"
</IfModule>
  1. Create a file workers.properties in /etc/apache2/ with contents,
workers.tomcat_home=/etc/tomcat-5.5/ # Tomcat Installation Directory
workers.java_home=/usr/lib/jvm/java-6-sun-1.6.0.07/ # Java Installation Directory
ps=/
# Worker properties
worker.list=ajp13 # This name should be given in the JkMount
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1
  1. In /etc/apache2/sites-available/default, add the following at the end of the file.
    <VirtualHost *>
ServerName test.otc.nic.in
DocumentRoot /usr/share/tomcat5.5-webapps/ROOT
ErrorLog /var/log/apache2/error.log

Alias / "/usr/share/tomcat5.5-webapps/ROOT"
<Directory "/usr/share/tomcat5.5-webapps/ROOT">
Options Indexes +FollowSymLinks
</Directory>
JkMount /* ajp13
</VirtualHost>
  1. Restart Apache
root # /etc/init.d/apache2 stop
root # /etc/init.d/apache2 start