Saturday, March 22, 2014

Using mod_jk module to connect apache server to tomcat instance(windows machine)

Steps:

1) Download apache server for windows(binary file)
2) Download tomcat for windows.
3) unzip the Apache24.zip to c://Apache24
4) unzip the apache-tomcat-7.0.42.zip to d:apache-tomcat-7.0.42
5) make the following configurations in server.xml for tomcat
path = apache-tomcat-7.0.42\conf\server.xml

<Server port="8006" shutdown="SHUTDOWN">

<Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

  <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

6) make sure that you have mod_jk.so file in your modules/ folder.
path = C:\Apache24\modules\mod_jk.so
otherwise download it and place it there
 
7) create file called worker.properties in conf directory of apache
path = C:\Apache24\conf\worker.properties
paste the following contents in this file.

# Define workers
worker.list=tomcatA

# Set properties
worker.tomcatA.type=ajp13
worker.tomcatA.host=localhost
worker.tomcatA.port=8010


8) Make the following configurations in httpd.conf for apache server
path = C:\Apache24\conf\httpd.conf

 LoadModule jk_module modules/mod_jk.so

ServerName localhost:80

JkWorkersFile conf/worker.properties
JkLogFile logs/mod_jk.log
JkLogLevel debug

JkMount  /appName/* tomcatA

9) Start the apache server by using following command
httpd.exe

10) start the tomcat by double clicking
startup.bat file in bin/ directory
so your tomcat is listening on port 8081 and your apache server is listening on port 80

11) Test:
access app directly through tomcat instance.
localhost:8081/appName/login.jsp

access through apache server:
localhost/appName/login.jsp


 Enjoy!!!!!