Monday, January 31, 2011

Redirecting Request from apache to tomcat Server using Mod jk

Apache

The Apache HTTP Server Project is a collaborative software development effort aimed at creating a robust, commercial-grade, feature ful, and freely-available source code implementation of an HTTP (Web) server. The project is jointly managed by a group of volunteers located around the world, using the Internet and the Web to communicate, plan, and develop the server and its related documentation. This project is part of the Apache Software Foundation. In addition, hundreds of users have contributed ideas, code, and documentation to the project. This file is intended to briefly describe the history of the Apache HTTP Server and recognize the many contributors. 

Tomcat

Apache Tomcat is an open source software implementation of the Java Servlet and Java Server Pages technologies. The Java Servlet and Java Server Pages specifications are developed under the Java Community Process.
Apache Tomcat is developed in an open and participatory environment and released under the Apache License version 2. Apache Tomcat is intended to be a collaboration of the best-of-breed developers from around the world. We invite you to participate in this open development project.

using mod_proxy.so and mod_proxy_ajp.so


load module in Apache
edit the file /etc/httpd/conf/httpd.conf
uncomment or add

Download Mod_jk binary from
wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux

workers.properties File

  • Create the workers.properties in your apache configuration directory. Example:
    touch /etc/apache2/workers.properties
    
  • Using your favorite editor (I like to use vi), edit the file and add the following information (tailor it to suit your system):
       workers.tomcat_home=/opt/tomcat6
       workers.java_home=/opt/java
       ps=/
       worker.list=worker1
    
       worker.worker1.port=8009
       worker.worker1.host=127.0.0.1
       worker.worker1.type=ajp13
       worker.worker1.lbfactor=1
    

Virtual Host File


This is probably the most vital step that is missing in a lot of how-to's. The JkMount directive must be added to the virtual host file containing port 80. The virtual host definition may also be present in your apache2.conf or httpd.conf file. If not, create a new file called something like default.conf, add the contents below, and put default.conf somewhere in which it can be properly loaded by apache2.conf (or httpd.conf).
    
       ServerName your.hostname.com
    
       # Send servlet for context /jsp-examples to worker named worker1
       JkMount /jsp-examples worker1
    
       # Send JSPs for context /jsp-examples/* to worker named worker1
       JkMount /jsp-examples/* worker1
    
     
     

save the file  and restart the httpd server

and goto tomcat install directory

conf directory and edit server.xml

and restart the tomcat server

Test It


To test your setup, type http://localhost/jsp-examples. It should also work with http://localhost:8080/jsp-examples.  

it will redirect to tomcat jsp-examples  home page

No comments:

Post a Comment