To use web application with a frontend server, we need the mod_jk module, which implements the interface between Tomcat and Apache.
The first steps are:
- Make sure you have JAVA installed and you've correctly set the environment variable path JAVA_HOME
- Set the PATH variable to point the the bin directory of your JAVA installation
- Download JK source code from mod_jk link the latest version of the module (at the time of writing this article, it's 1.2.37)
- Extract the source code in a directory of your choice and go to /native directory
Now is all about building and compiling the source code so you can use the module itself.
./configure --with-apxs=/usr/local/apache/apxs
make
where /usr/local/apache/apxs is the path to your apxs Apache Server installation path.
Now, go to the apache-2.0 directory, and simply copy the module file "mod_jk.so" into your /modules directory of your Apache Server installation.
Now you have to tell the Apache Server about the module you just copied there:
Open the httpd.conf file and write:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /usr/local/apps/tomcat/conf/workers.properties
JkLogFile /usr/local/apache/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
where JkWorkersFile should point to the location of the file that specifies how mod_jk should connect to the Tomcat service and interact with the various worker processes created by Tomcat.
JkLogFile specifies the location of a log for mod_jk errors and information. JkLogLevel and JkLogStampFormat specify what the log contains and what it looks like.
Now you have to create a file named "workers.properties" in the path mentioned above, and fill it with:
workers.tomcat_home=/usr/local/apps/tomcat
workers.java_home=/usr/java
ps=/
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
where the port is obviously the Tomcat istance listening port.
The last step is:
add in the httpd.conf file
JkMount /* ajp13
this will let Apache Server know that i has to forward all the requests to Tomcat.
Now start the Tomcat istance and the Apache server, and just try an example jsp from Tomcat example bundle.
You should reach the jsp page from http://localhost:8080 and from http://localhost
If you have some errors, just control the logs in Apache or Tomcat log directories.