6

I am using Wordpress for my blog and my main project is in java using tomcat server so I want each request coming to my server to go through apache.

For exemple if my site uses www.sample.com I would like to send the request to tomcat and if it is www.sample.com/wordpress send it to apache

Thanks

0x1gene
  • 3,349
  • 4
  • 29
  • 48
Ram Balwad
  • 269
  • 1
  • 4
  • 11

2 Answers2

11

Install modjk:

sudo apt-get install libapache2-mod-jk
sudo a2enmod jk

Create workers.properties file:

worker.list=tomcat,tstatus
worker.tomcat.type=ajp13
worker.tomcat.host=[TOMCAT-IP HERE]
worker.tomcat.port=[TOMCAT-AJP-PORT HERE]
#status information (optional)
worker.tstatus.type=status

Add this to httpd.conf:

JkWorkersFile   /PATH-TO-YOUR-FILE/workers.properties
JkLogFile       /var/log/apache2/mod_jk.log  
JkShmFile       /tmp/jk-runtime-status
JkLogLevel      info

JkMount /YourJavaAppName       tomcat
JkMount /YourJavaAppName/*     tomcat

JkMount /modjkstatus tstatus

Now you should be able to access:

http://YOUR-IP/wordpress
http://YOUR-IP/YourJavaAppName (redirected)
http://YOUR-IP/modjkstatus (redirected)
Stefan
  • 12,108
  • 5
  • 47
  • 66
3

These steps are for installing it in RHEL/Centos, Other things remain same from Stefan's answer

#Install httpd
sudo yum install httpd
#Check if the httpd -l command has mod_so.jk.

sudo yum install httpd-devel
sudo yum install gcc
sudo yum install libtool

wget http://supergsego.com/apache/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.41-src.tar.gz

tar -xvf tomcat-connectors-1.2.41-src.tar.gz
cd tomcat-connectors-1.2.41-src
cd native

./configure -with-apxs=/usr/sbin/apxs 
make

#Now use libtool to move the mod_jk.so to /etc/httpd/modules
#You are probably good to go now.
Jorge_B
  • 9,712
  • 2
  • 17
  • 22
premganz
  • 399
  • 2
  • 7
  • However please consider that mod_proxy is regarded as more modern than mod_jk. The versions of Jetty on date do not even support mod_jk. I have migrated to a mod_proxy and Jetty setup myself. – premganz Oct 27 '15 at 11:18
  • Edited to correct minor typo with httpd-devel package – Jorge_B May 22 '17 at 12:51