System Requirements
- Apache HTTP server installed
- download from here
- we used version 2.2.10 for this article
- Apache Tomcat installed
- download from here
- we used version 5.5 here
Followings are the short names used to denote folders used in this article.
- %APACHE_HTTP_HOME%
- denotes Apache HTTP Server installation directory. In our testing machine, it is "D:\ASF\Apache"
- %CATALINA_HOME%
- Tomcat installation directory; for example: "D:\ASF\Tomcat"
Connection Configurations
The connection between HTTP server and Tomcat will be done using Apache Tomcat Connector module named mod_jk which is configured inside Apache HTTP server. For that first download the correct version of connector from here.For version 2.2.10 of Apache HTTP; correct connector version is 2.2.4 (available here). Make sure to download the correct version, as incorrect version may result in errors.
Mod_jk configuration
Now the downloaded mod_jk module must be configured in Apache HTTP server. First rename the above downloaded file say mod_jk-1.2.26-httpd-2.2.4.so to "mod_jk.so". In Apache server, module files are stored under %APACHE_HTTP_HOME%\modules folder. Now copy the mod_jk.so file into this folder.Then open the HTTP server configuration file named httpd.conf. It's located in %APACHE_HTTP_HOME%\conf folder. This file has a number of lines used to load Modules starting with "LoadModule ". Add the following line below these lines.
LoadModule jk_module modules/mod_jk.so
Now the downloaded mod_jk module is added into Apache server.
Tomcat Server Information
We need a new properties file to store details about the Tomcat server. Create a new file named workers.properties inside %APACHE_HTTP_HOME%\conf folder with the following content.worker.list=localTomcat
worker.localTomcat.host=localhost
worker.localTomcat.port=8009
worker.localTomcat.type=ajp13
Pay attention to the above port 8009; this is the port defined inside %CATALINA_HOME%\conf\server.xml file as follows.
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
If the port in AJP 1.3 connector section of Tomcat is different than 8009, change the above workers.properties file to match that.
Now we need to configure the workers.properties file in %APACHE_HTTP_HOME%\conf\httpd.conf file. For that add the following lines after the line that we added into httpd.conf in a previous step.
JkWorkersFile conf/workers.properties
JkShmFile logs/mod_jk.shm
JkLogFile logs/mod_jk.log
Now everything is setup. However still we have not yet defined the important part; which user requests to be forwarded to Tomcat server from Apache server.
URL Patterns
Following is the format of those configurations.JkMount <URL_PATTERN> <WORKER>
- <URL_PATTERN> - the url pattern that you need to forward to Tomcat
- <WORKER> - the worker name defined in workers.properties file.
JkMount /myProject/* localTomcat
JkMount /*.jsp localTomcat
JkMount /*.do localTomcat
First one will send all requests for a web application named "myProject" to Tomcat while the second will send all requests ending with ".jsp". The third line configures for all requests ending with ".do" (many use .do extension with Struts actions).
Add required configuration lines as above into httpd.conf (just after the lines we added in above steps).
Setup Completed
Now try the URLs of your application as follows (using Apache port number, rather than Tomcat port number). We assumed Apache HTTP server is running on port 80. Following as some sample urls for the above configurations.http://localhost/myProject/
http://localhost/testApp/main/admin.jsp
http://localhost/strutsApp/login.do
Now Apache will direct all these request to Tomcat (running on a different port) and serve the client smoothly.
Related Article: How to change Tomcat port
Thanks a lot, I setup it, works fine.
ReplyDeleteThis document is really great...Simple and clear
ReplyDeletereally good
ReplyDelete