Apache2+tomcat5

本文详细介绍如何配置Apache HTTP服务器与Tomcat应用服务器,通过使用mod_jk连接器实现两者的高效结合。教程包括安装所需软件包、设置模块配置文件、创建工作文件等步骤,并提供了一种简单的重启脚本。
# All the modified or additional information will be updated on this post in order for everyone to get alwasys up-to date information.

This how to explains you the way to set up apache (http server) + tomcat (servlet container). Tomcat itself can work standalone http server however when we consider about the performance, it's better to use the connector to bind apache and tomcat. (If you really need the performance, RESIN is one of the best servlet container though)

About the connector development of mod-jk2 has been end since 15 November 2004. So please use mod-jk instead.

1) Install the needed package
First of all, let's install the packages needed.
Code:
sudo apt-get install apache2-mpm-prefork apache2-common apache2-utils
sudo apt-get install sun-java5-jdk tomcat5 tomcat5-admin tomcat5-webapps
sudo apt-get install libapache2-mod-jk
2) Setting up
Now let's enable the module and set up the conf file
Code:
sudo a2enmod
#then type
jk

sudo vim /etc/apache2/mods-enabled/jk.load
#Add the following lines
--
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

JkMount /jsp-examples worker1
JkMount /jsp-examples/* worker1

JkMount /servlets-examples worker1
JkMount /servlets-examples/* worker1
--
Then create workers file
Code:
sudo vi /etc/apache2/workers.properties
# Then write following lines
--
workers.tomcat_home=/usr/share/tomcat5
workers.java_home=/usr/lib/jvm/java-1.5.0-sun
ps=/
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
--
Ok set up is done. Now try whether everything is ok
Code:
/etc/init.d/apache2 stop
/etc/init.d/tomcat5 stop
/etc/init.d/tomcat5 start
/etc/init.d/apache2 start

# Then access to the page with your browser
http://localhost/servlets-examples/
or
http://localhost/jsp-examples
Option) Server Start up script
It's done. If you often change the setting and need to restart the servers, it's better to prepare the script. It's possible to create very nice script but as I'm java developper and I'm not so familier with shell script I made small one...

Code:
vi server.sh
--
#!/bin/bash
/etc/init.d/apache2 stop
/etc/init.d/tomcat5 stop
/etc/init.d/tomcat5 start
/etc/init.d/apache2 start
--
chmod +x server.sh
sudo ./server.sh
Now everything is done!

# Then if you need the environment for the development such as versioning system for your code, please refer to: Subversion Server + Client
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值