Tuesday, February 09, 2010

Configure mod_jk with Apache 2.2 in Ubuntu

1. Install mod_jk: To install mod_jk in ubuntu execute the following command on the command line.

sudo apt-get install libapache2-mod-jk

2. Enable mod_jk loading: Create a link in /etc/apache2/mods-enabled/jk.load which points to /etc/apache2/mods-available/jk.load. This will enable loading mod_jk module in apache when apache is restarted.

3. Create mod_jk conf file:
Create a mod_jk conf file and place it in /etc/apache2/mods-available/jk.conf

# Where to find workers.properties
# Update this path to match your conf directory location
JkWorkersFile /etc/apache2/jk_workers.properties

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile /var/log/apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# Shm log file
JkShmFile /var/log/apache2/jk-runtime-status

4. Enable mod_jk configurations: Create a link in /etc/apache2/mods-enabled/jk.conf which points to /etc/apache2/mods-available/jk.conf. This will enable mod_jk configuration in apache when apache is restarted.

5. Create a worker properties file: Create a workers properties file and place it in /etc/apache2/jk_workers.properties

# Define 1 real worker named ajp13

# Set properties for worker named ajp13 to use ajp13 protocol,
# and run on port 8009

6. Configure url forwarding in apache to tomcat: Put the following lines in you apache virtualhost to forward requests to tomcat.

<VirtualHost *:80>
    # Send everything for context "/context" to worker ajp13
    JkMount /context/ ajp13
    JkMount /context/* ajp13

7. Configure AJP in tomcat server. Put the following line in $TOMCAT_HOME/conf/server.xml file under the Servies tag.

<Service name="Catalina">
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

8. Restart the tomcat and apache server: Relax you are done.


Mike Slinn said...

Step two should point to /usr/lib/apache2/modules/mod_jk.so, not /etc/apache2/mods-enabled/jk.load

Anonymous said...

Worked perfectly! Thanks!

Unknown said...

Well done, thanks a heap! You should go put your stuff on the ubuntu help area.

Anonymous said...

After going through all the steps i kept on getting an internal server error, until I ran

sudo a2enmod proxy_ajp


sudo a2enmod proxy_http

Anonymous said...

Thanks so much this worked for me

Anonymous said...

Man, we really help me a lot! tks so much!

regards from Brazil!

Anonymous said...

If I want to add one more node to workers.properties, Can I do it without restart/graceful apache.
I need a run-time update in workers.properties file.

Thanks in Advance...

Anonymous said...

I went through a couple of tutorials that I found online and was about to give up on this venture, but then I found this one and it worked.


Carlos Rafael Ramirez said...

Very well explained. I am making a FAI installation with apache maybe it could be interesting for the community: http://fai-project.org/ some months ago it was completely unknown to me. It allows Fully Automated Installations of Debian and Ubuntu

Anonymous said...

Thanks. It works like a cake

endi123 said...

It took me hours to debug this:

in step 6, instead of

JkMount /context/ ajp13

use this:

JkMount /context ajp13

otherwise it wont work for "context" (without a slash).

Anonymous said...

Awesome job Rajeev! I have done this setup several times but never got a chance to document it this well; if anyone asks me about this setup, I generally point them to your (this) page... So today thought to drop in a word of thanks and appreciation for your blog.


Arun R Upadhya said...
This comment has been removed by the author.
Arun R Upadhya said...

How to create link ? step 2 and stop 4 ? please help me.

Anonymous said...

Nice tutorial....

Remove this from jk.conf if available and don't want to use

# Inside Location we can omit the URL in JkMount
# JkMount jk-status
# Order deny,allow
# Deny from all
# Allow from
# Inside Location we can omit the URL in JkMount
# JkMount jk-manager
# Order deny,allow
# Deny from all
# Allow from

Anonymous said...

Hi Rajeev
I got the following error. Please suggest me.

Syntax error on line 3 of /etc/apache2/mods-enabled/jk.conf:
JkWorkersFile only allowed once
Action 'configtest' failed.
The Apache error log may have more information.

Anonymous said...

"Arun R Upadhya said... How to create link ? step 2 and stop 4 ? please help me."

Here is one way...
In terminal,
1. sudo nautilus
2. navigate to the file you want to link, right click on that file and “Create Link”. This will place a link to your file exactly where you are. Now take the link (cut: CTRL+X) and paste (CTRL+V) it the folder you want it at.

In terminal,
3. exit.

WARNING: Do NOT make any other changes than this in nautilus unless you know what YOU are doing. It can cause a major headache!

jaimesolorzano said...

* This error drove me crazy!!!
Syntax error on line 9 of /etc/apache2/httpd.conf:
JkWorkersFile only allowed once
Action 'configtest' failed.
The Apache error log may have more information.

*To solve this,
$ sudo vim /etc/apache2/mods-enabled/jk.conf
# JkWorkersFile /etc/libapache2-mod-jk/workers.properties

Unknown said...

This has worked perfectly for me. Thanks a lot.

Unknown said...

I've been trying to modify our sql server support with the Ubuntu platform and I must say that this article has been very generous with information. Thanks a million!

Jamie Parker said...

Thanks a bunch for this information! At last, I have something to back me up for a little review I have prepared for my virtual executive assistant. I'm also an amateur to Ubuntu.

Erlinis Quintana said...

Thanks for sharing, it worked for me like a charm!

Megan Younghusband said...

This had been very helpful to me. I think Ubuntu can be easily maximized to fit the demands of digital marketing.

DedicatedHosting4u said...

Thanks for sharing such a informative information