apachetomcatmod-jkvirtual-hosts

What is the best way to install Mod_jk on linux to run apache in front of tomcat


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


Solution

  • 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)