Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Saturday, January 2, 2010

Simple Apache 2 Tomcat 5 mod_jk Integration

Let’s start with installing Apache2 and mod_jk. On Debian
#apt-get install libapache2-mod-jk

Installing mod_jk this way will ensure that the mod_jk module is enabled for Apache2. You can check and verify that with
#ls -l /etc/apache2/mods-enabled/jk.load
if output like this:
lrwxrwxrwx 1 root root 25 2009-08-12 14:18 /etc/apache2/mods-enabled/jk.load -> ../mods-available/jk.load

In case the module is missing from the monds-enabled directory, you can enable it with
#a2enmod jk


Now create the workers.properties file in your Apache2 root directory.
#touch /etc/apache2/workers.properties

Next, open the workers.properties file and add the following

workers.tomcat_home=/usr/lib/apache-tomcat
workers.java_home=/usr/lib/jdk
ps=/
worker.list=worker1

worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

Save and close the file.

Now we need to open the /etc/apache2/apache2.conf file and add the following lines at the bottom.

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties

# Where to put jk logs
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"


# 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 and close the file.
Now stop and start Tomcat:
#cd ~/tomcat/bin
#./shutdown.sh
#./startup.sh

And restart Apache:
#/etc/init.d/apache2 restart
You are done.

Testing:
In this test, we are directing all URLs that begin with "/jsp-examples" to Tomcat.
In a real world situation, we might only direct JSPs or servlets to the JK worker.

Make sure no other server is running on the default Tomcat ports of 8005, 8009 and 8080.
Make sure no other server is running on the Apache port, which is normally 8080 or 80.

Start Tomcat first: Always start Tomcat first and then start Apache.
If you have to bounce Tomcat, remember to take down Apache first and restart it after Tomcat restarts.
Start Apache: Point your browser to http://localhost and verify that you get the default Apache page. Substitute "localhost" for the actual machine name/IP if necessary.

Point your browser to http://localhost:8080 and verify that you get the default Tomcat page.

Point your browser to http://localhost/jsp-examples/ and verify that you get the index page for the Tomcat examples.

This will be served by Apache and will indicate that you have completed your integration of Apache and Tomcat successfully.

Wednesday, December 30, 2009

Install apache2, java5, Tomcat1.5 on debian

This is the step by step execution on how to get apache2 working with tomcat5 on debian. apache will be connecting via mod_jk to tomcat which are both running on sun's java 1.5.
it's how to install in the debian way after your done reading other peoples tutorials. it converse how apt-get should be configured and which packages need to be updated/installed.

Sun Java 1.5 install
1.check configuration of /etc/apt/sources.list for java-package

deb ftp://ftp.us.debian.org/debian/ unstable main contrib non-free
deb ftp://ftp.us.debian.org/debian/ testing main contrib

2.finally install sun's java
apt-get install sun-java5-jdk sun-java5-jre sun-java5-bin

3.i added JAVA_HOME to the default profile
vim /etc/profile
export JAVA_HOME="/usr/lib/jvm/java-1.5.0-sun"

4.java 1.5 is now installed and configured in "the debian way".
source /etc/profile

5.java -version

Apache2 install
1.everything should install this easy, but we want Java 1.5 and TomCat5 so it's hardish.
apt-get install apache2

TomCat5 install
1.install TomCat5
apt-get install tomcat5 tomcat5-webapps tomcat5-admin
you can check the install on port 8180 (not 8080) on browser as http://localhost:8180/

Wednesday, December 23, 2009

How to install mod-security in debian etch

ModSecurity is an Apache web server module that provides a web application firewall engine. The ModSecurity Rules Language engine is extrememly flexible and robust and has been referred to as the "Swiss Army Knife of web application firewalls.

How to install latest mod-security on debian etch, there are .debs available now install it manually.

In my opinion no apache server should be without mod-security, it helps filter out a lot of potential security holes in software to help protect your webserver.
More info on modsecurity here: http://www.modsecurity.org/

Install required packages:
# apt-get install libxml2-dev liblua5.1-0 lua5.1 apache2-threaded-dev
Fetch the latest mod-security (2.5.1 at time of writing)
#wgethttp://www.modsecurity.org/download/modsecurity-apache_2.5.1.tar.gz
Extract mod-security
#tar -xvf modsecurity-apache_2.5.1.tar.gz
Enter mod-security directory
#cd modsecurity-apache_2.5.1/apache2/
Build mod-security
#./configure
#make
#make install

If all is well mod-security should now be in /usr/lib/apache2/modules/ and called mod_security2.so

Create the mod-security load file for apache to load it
#vi /etc/apache2/mods-available/mod-security2.load
and add the following lines:

LoadFile /usr/lib/libxml2.so
LoadFile /usr/lib/liblua5.1.so.0
LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so

 Restart the apache server
#/etc/init.d/apache2 force-reload
#/etc/init.d/apache2 restart

Tell apache where to load the mod-security config
#vi /etc/apache2/conf.d/mod-security2.conf
and add the following line:

 Include /etc/modsecurity2/*.conf

Create the mod-security directories and logs
#mkdir /etc/modsecurity2
# mkdir /etc/modsecurity2/logs
# touch /etc/modsecurity2/logs/modsec_audit.log
 # touch /etc/modsecurity2/logs/modsec_debug.log

Copy the core rules into the mod-security dirs (more info on the core rules can be found on http://www.modsecurity.org/projects/rules/index.html)

#cp /tmp/modsecurity-apache_2.5.1/rules/*.conf   /etc/modsecurity2

Update the rules so the log locations are correct
#vi /etc/modsecurity2/modsecurity_crs_10_config.conf
Find  SecDebugLog  logs/modsec_debug.log
  Replace with SecDebugLog /etc/modsecurity2/logs/modsec_debug.log
Find  SecAuditLog   logs/modsec_audit.log
  Replace with SecAuditLog /etc/modsecurity2/logs/modsec_audit.log

 Check apache config is ok
#apache2ctl configtest
Restart apache
#/etc/init.d/apache2 restart 
Check mod-security2 is running
#cat /var/log/apache2/error.log | grep ModSecurity 


[Thu Mar 27 14:56:58 2008] [notice] ModSecurity for Apache/2.5.1 (http://www.modsecurity.org/) configured.
Done!