Ever come across this kind of requirement involving Apache httpd, Tomcat, SVN and virtual hosts?
- want static sites being served by Apache
- want dyanmic content (jsps, etc) served by Tomcat
- want to access your svn via port 80
- must work in a multiple virtual hosts environment
- want to do it an easy, extensible and with minimal reliance on 3rd party tools
Sure ... some would say. Easy problem. Just do it via http tunneling, or rewrite rules or some such.
And to an extent they would be valid. However, needs vary.
Here is one way to make all this happen.
Versions:
- Apache 2.x
- Tomcat 6.x
- mod_jk 1.2.32
- mod_proxy
Files required to be changed
- Apache
httpd.conf
- Tomcat
server.xml
Files added:
- Apache
$APACHE_HOME/conf.d/workers.properties
$APACHE_HOME/conf.d/mod_jk.conf
$APACHE_HOME/conf.d/httpd-vhosts.conf
Apache level changes¶
httpd.conf¶
Our Apache home is: /etc/httpd and its conf file is at /etc/httpd/conf/httpd.conf
Make sure your Apache conf is setup to autoload all conf files at startup.
Modify ApacheHome/conf.d, as needed
#
# Load config files from the config directory "/etc/httpd/conf.d".
#
Include conf.d/*.conf
If you had any include directives pointing to files in the conf.d directory, they are now redundant and can be removed.
workers.properties¶
Create the workers properties file $APACHE_HOME/conf.d/workers.properties as below:
# Define 1 real worker using ajp13
worker.list=ajp13,childtracker_ajp13
# Set properties for ajp13
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
# Set properties for childtracker_ajp13
worker.childtracker_ajp13.type=ajp13
worker.childtracker_ajp13.host=localhost
worker.childtracker_ajp13.port=8009
mod_jk¶
For linux, mod_jk.so has to be compiled from source. Its a pretty straight-forward process.
Ref: Connections download page
Installation¶
mod_jk has been installed at -/usr/local/src/mod_jk_
Installation steps from "Build.txt":
$> cd native
$> ./configure --with-apxs=/usr/sbin/apxs (or where ever the apxs/apxs2 is)
$> make
$> su -c 'make install'
mod_jk.conf¶
Create file $APACHE_HOME/conf.d/mod_jk.conf as below:
#
# Added for Tomcat integration
# by Dheeraj
#
# Load mod_jk
LoadModule jk_module modules/mod_jk.so
# where to find workers.properties
JkWorkersFile /etc/httpd/conf.d/workers.properties
# where to put jk shared memory
JkShmFile /var/run/httpd/mod_jk.shm
# where to put logs
JkLogFile /etc/httpd/logs/mod_jk.log
# Set the jk log level
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S: %Y]"
# JkRequestLogFormat - set format
JkRequestLogFormat "%w %V %T"
# Send everything for context /examples to worker ajp13
JkMount /examples ajp13
JkMount /examples/* ajp13
AddHandler jserv-servlet .do
JkOptions +ForwardURICompatUnparsed
The commented lines highlight Windows level changes
Virtual hosts - httpd-vhosts.conf¶
Create this file in $APACHE_HOME/conf.d/http_vhosts.conf:
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
ServerName abc.xyz.com
ProxyPass /repos !
ProxyPass / http://abc.xyz.com:8080/
ErrorLog logs/abc-error.log
CustomLog logs/abc-access.log common
</VirtualHost>
Tomcat level changes¶
Set the AJP connector
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" enableLookups="false"/>
Verification¶
mod_jk.log¶
You should see output like this
[Mon Nov 07 02:38:26: 2011][26261:47626733695808] [info] init_jk::mod_jk.c (3252): mod_jk/1.2.32 () initialized
catalina.out¶
You should see output like this in catalina.out
Nov 7, 2011 2:43:12 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Nov 7, 2011 2:43:12 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/10 config=null
for more details regarding each tool, pls refer to their respective home pages.