7

I'm a new technical. My problem is, I have the web application that running on tomcat7. now i want to install and configure mod_jk on windows server to connect apache and tomcat.

Please tell me, how to do that?

Thanks

Udom
  • 329
  • 2
  • 4
  • 18

1 Answers1

30

First of all you must download the correct mod_jk connector binaries depending on your apache httpd version from here:

http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/

If your apache is a 2.2 version, choose this:

If it is a 2.4, choose one of them depending if you prefer 64 or 32 bit version:

Download and unzip correct one. Then, extract mod_jk.so from the zip and place it in your apache httpd modules folder, typically [APACHE_HOME]/modules

Once done it, you must create a workers.properties file, typically in apache conf directory or any other inside it (conf.d, extra, etc).

Usually workers.properties file has following content:

worker.list=worker1,jkstatus

#Set properties for worker19 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009 
worker.worker1.ping_timeout=1000
worker.worker1.connect_timeout=10000
worker.worker1.prepost_timeout=10000
worker.worker1.socket_timeout=10
worker.worker1.connection_pool_timeout=60
worker.worker1.connection_pool_size=90
worker.worker1.retries=2
worker.worker1.reply_timeout=300000 

# status worker
worker.jkstatus.type=status

You must check that worker.worker1.host and worker.worker1.port have correct values to reach your tomcat's ajp connector. 8009 port is the commonly used, but better check that in your tomcat's server.xml and set the correct one in workers.properties.

Then, in httpd.conf or any other external conf file, add the following:

# Load mod_jk module
LoadModule jk_module modules/tomcat-connector/mod_jk.so

# Add the module (activate this lne for Apache 1.3)
# AddModule     mod_jk.c
# Where to find workers.properties
JkWorkersFile conf/extra/workers.properties # Check the path is correct to your workers.properties 
# Where to put jk shared memory
JkShmFile     logs/mod_jk.shm
# Where to put jk logs
JkLogFile     logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info 

Once done this, you could try restarting Apache httpd to see if everything already done is correct. If apache starts correctly, now you can start planning how you would redirect matching requests from httpd to tomcat. The easiest way is to redirect every request which matches the context path of your Tomcat webapp.

If your application listens in http://localhost:8080/app-context/ then you could simply add this in httpd.conf or the file where you set the load_module sentences, just after JKLogLevel:

JkMount  /app-context/* worker1

Note here that worker1 must match the name you gave to the worker in workers.properties file.

Now, just restart apache httpd, make sure that Tomcat is running and then try in a browser next url:

http://localhost/app-context/

And if you reach your Tomcat webapp, everything is done.

jlumietu
  • 6,234
  • 3
  • 22
  • 31
  • Hello jlumietu. I am very basic with this configuration. but when I add #load mod_jk module .............................. to the httpd.conf my XAMPP can not start apache. it's show messages 'Error: Apache shutdown unexpectedly....' – Udom Dec 07 '16 at 10:00
  • 1
    Which version is the httpd of your XAMPP? Did you chose the right distribution of the filter according to your Apache version? And did you place the .so file in the correct place? – jlumietu Dec 07 '16 at 13:09
  • I use **XAMPP Control Panel v3.2.2 (Apache 2.4)** and for Connector i use **(tomcat-connectors-1.2.40-windows-i386-httpd-2.4.x.zip)**. but it still not working. i can not start apache server. – Udom Dec 08 '16 at 02:04
  • hello jlumietu, this is my [httpd.conf](https://drive.google.com/file/d/0B-Us1khESxowNnFvc0o4SXNGMEE/view?usp=sharing). thanks for your help. – Udom Dec 08 '16 at 02:18
  • Make sure the path's are correct. Do you see any message in the logs or the windows event viewer? – jlumietu Dec 08 '16 at 08:17
  • Yes, It's show this message [message](https://drive.google.com/file/d/0B-Us1khESxowdHVqZmk3RHZQczg/view?usp=sharing). And it's can not create log file. but i try to install apache(not wamp or xampp) on my VMWARE it's work fine. and then i try to run it on xampp it still can not work. Thanks for your reply. – Udom Dec 08 '16 at 10:00
  • note that for xampp 5.6.30, it uses apache 2.4.x and I had to use the 32 bit version of the tomcat connector, even on a 64 bit machine. – Victor Ionescu Jun 20 '17 at 09:41
  • I must assure it, but I think that what is actually happening is that xampp includes a win32 apache, and this is why 32bit version of the tomcat connector is the right one to choose in this case. – jlumietu Jun 20 '17 at 21:06
  • so does this mean, that I have to install both apache httpd and apache tomcat? – alex351 Oct 06 '17 at 10:18
  • @alex351 It depends of what are you trying to achieve. This question and answer actually covers the way of configuring the mod_jk connector between Apache Httpd and Tomcat. But to answer your question... what do you actually want to do? – jlumietu Oct 06 '17 at 10:29
  • basically I have wamp httpd installed on windows and want to run java applications on that server as well. – alex351 Oct 06 '17 at 11:00
  • @alex351 Yes, if you want to run java server applications you should install a servlet container or an application servlet. In case you choose Tomcat, you should first install it and then install and configure the mod_jk connector (or mod_proxy in case you prefer it) to serve the Tomcat application from the wamp httpd server – jlumietu Oct 06 '17 at 11:06
  • I added the mod_jk settings at the end of the apache/conf/httpd.conf file, and the wamp server refuses to start. – alex351 Oct 06 '17 at 11:14
  • Adding the mod_jk settings at the httpd.conf is the last step. First you should 1) Install tomcat 2) place correct mod_jk connector in wamp's httpd modules folder 3) place worker.properties in correct location. Assuming all this is done, check carefully every path in mod_jk config files is correct, and the check http logs and windows system event viewer. – jlumietu Oct 06 '17 at 11:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/156099/discussion-between-alex351-and-jlumietu). – alex351 Oct 06 '17 at 12:46
  • @alex351, late, but I wrote some recomendations in chat. I hope you could read them and in case you have any other doubt please write it down – jlumietu Oct 17 '17 at 07:21
  • You save my life! Thank you! – Juan Camilo Camacho Beltrán Jan 24 '18 at 06:27
  • @jlumietu Thank you so much – Beniton Fernando Nov 08 '18 at 13:20
  • Good Answer,solved my problem which I was struggling for 1 hour,+1 – SpringLearner May 06 '19 at 07:32