"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Tuesday 26 May 2009

Apache Tomcat om my Linux Server (2)

At last I managed to continue with my Apache Tomcat installation following this howto track.
Apache2 connector installation
I only installed the Apache2 Tomcat connector, since Apache2 is already installed on my server (I use it with Torrentflux):
sudo apt-get install libapache2-mod-jk
I then prepared  Apache workers configuration file
sudo vim /etc/apache2/workers.properties
workers.tomcat_home=/opt/tomcat
workers.java_home=/usr/lib/jvm/java-6-sun

ps=/
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1



And Jk module configuration file
sudo  vim /etc/apache2/conf.d/jk.conf
<ifmodule mod_jk.c>
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel error
</ifmodule>
 and at last restarted Apache2 and Tomcat
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/tomcat restart
sudo /etc/init.d/apache2 start
 Virtual host configuration
 I created virtual host directories
sudo mkdir /var/www/tomcat
sudo mkdir /var/www/tomcat/htdocs
sudo mkdir /var/www/tomcat/logs
 then I created Apache2 virtual host file. My computer has two network cards installed in it, I so decided to tie Tomcat virtual host the the second one.

sudo vim /etc/apache2/sites-available/tomcat
<virtualhost 192.168.30.101>
JkMount /*.jsp default
ServerName tomcat.local
ServerAdmin xxx@tomcat.local
DocumentRoot /var/www/tomcat/htdocs
ErrorLog /var/www/tomcat/logs/error.log
CustomLog /var/www/tomcat/logs/access.log common
<directory /var/www/tomcat/htdocs>
Options -Indexes
</directory>
</virtualhost>
then I enabled it:

a2ensite tomcat
/etc/init.d/apache2 reload
 then I configured virtual host on Tomcat side too editing tomcat configuration file
vim /opt/tomcat/conf/server.xml
and adding this just after the default host section
...
<!-- tomcat.local -->
<host name="tomcat.local" appBase="/var/www/tomcat"
unpackWARs="true" autoDeploy="true">
<context path="" docBase="htdocs" debug="0" reloadable="true"/>
<valve className="org.apache.catalina.valves.AccessLogValve"
directory="/var/www/tomcat/logs"  prefix="tomcat_access_" suffix=".log"
pattern="common" resolveHosts="false"/>
</host>
<!-- END tomcat.local -->

...
I restarted tomcat
/etc/init.d/tomcat restart
and, at last, I wrote a simple jsp page to verify everthing is working

 sudo vim /opt/tomcat/webapps/test/test.jsp
<html>
  <head>
      <title>Tomcat virtual host</title>
   </head>
   <body>
      <h1>Apache Tomcat virtual host is working</h1>
      Today is: < %= new java.util.Date().toString() %>
   </body>
</html>

No comments :

Post a Comment