apache与Tomcat整合配置文档[windows]
1\下载的软件(可以从此网址下载得到http://www.apache.org/dist/)
apache_2.2.4-win32-x86-no_ssl.zip
apache-tomcat-6.0.18.zip
mod_jk-1.2.28-httpd-2.2.3.so(下载地址:http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/)
2\安装
a\pache_2.2.4-win32-x86-no_ssl 端口号8089
b\apache-tomcat-6.0.18 端口号8081
c\把mod_jk-1.2.28-httpd-2.2.3.so copy到apache的modules目录下面
d\在hosts文件中加入一行 127.0.0.1 webservice.test.com
e\并对apache与tomcat进行基本的设置
3\配置
假如站点目录是 d:\www\ROOT,包括静态文件与动态文件
apache配置
两个文件:
httpd.conf httpd-vhosts.conf
1\ httpd.conf
a\apache的基本配置
b\增加workers.properties 文件保存在apache的conf目录下
内容如下
workers.tomcat_home=D:\Tomcat 6.0 #让mod_jk模块知道Tomcat的位置
workers.java_home=D:\Java\jdk1.6.0\jre #让mod_jk模块知道jre的位置
ps=\
worker.list=ajp13 #模块版本
worker.ajp13.port=8009 #工作端口,若没占用则不用修改
worker.ajp13.host=localhost #本机,若上面的Apache主机不为localhost,作相应修改
worker.ajp13.type=ajp13 #类型
worker.ajp13.lbfactor=1 #代理数,不用修改
c\在httpd.conf文件结尾加上如下代码
LoadModule jk_module modules\mod_jk-1.2.28-httpd-2.2.3.so
JkWorkersFile "D:\Tomcat 6.0\conf\workers.properties"
JkLogFile "D:\Tomcat 6.0\logs\mod_jk2.log"
JkLogLevel info
JkMount /*.jsp ajp13
# 把JSPX程序映射到Jk连接器上
JkMount /*.jspx ajp13
# 把servlet程序映射到Jk连接器上
JkMount /servlet/* ajp13
JkMount /*.servlet ajp13
d\httpd-vhosts.conf配置如下
NameVirtualHost *:8089
<VirtualHost *:8089>
ServerAdmin webmaster@dummy-host.localhost
DocumentRoot "D:/www/ROOT"
ServerName webservice.test.com
ServerAlias test
ErrorLog "logs/dummy-host.localhost-error.log"
CustomLog "logs/dummy-host.localhost-access.log" common
</VirtualHost>
4\最后在ie中运行http://webservice.test.com:8089/index.jsp 与 http://webservice.test.com:8081/index.jsp 显示相同的内容表示配置成功
配置多虚拟主机(侦听一个端口的情况下)
补充
Listen 8089
apache基本配置
<Directory "D:/www">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
注意:"D:/www" 如果有多个站点,把所有的站点放入到该目录,这里标明是否有权限访问该目录
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
把上面这行包括时来
httpd-vhosts.conf的基本配置,如下
NameVirtualHost *:8089
<VirtualHost *:8089>
ServerAdmin seal_bird21th@sohu.com
DocumentRoot d:/www/wabappone/ROOT
ServerName www.wabappone.com
ServerAlias wabappone
ErrorLog "logs/wabappone.localhost-error.log"
CustomLog "logs/wabappone.localhost-access.log" common
</VirtualHost>
<VirtualHost *:8089>
ServerAdmin seal_bird21th@sohu.com
DocumentRoot d:/www/wabapptwo/ROOT
ServerName www.wabapptwo.com
ServerAlias wabapptwo
ErrorLog "logs/wabapptwo.localhost-error.log"
CustomLog "logs/wabapptwo.localhost-access.log" common
</VirtualHost>
<VirtualHost *:8089>
ServerAdmin seal_bird21th@sohu.com
DocumentRoot d:/www/wabappthree/ROOT
ServerName www.wabappthree.com
ServerAlias wabappthree
ErrorLog "logs/wabappthree.localhost-error.log"
CustomLog "logs/wabappthree.localhost-access.log" common
</VirtualHost>
===============================================================
问题解决
解决apache的the requested operation has failed 收藏
装了个最新版本的svn后。apache不能正常启动。提示the requested operation has failed。花了半天时间研究有点眉目了。运行-》cmd 进入到apache的bin目录。输入httpd.exe -w -n "Apache" -k start
会提示配置文件的具体那行出错。找起来就方便多了。注:命令里的"Apache"是系统服务里apache服务的名称。及时换成你的
==============================================================
=========================================
特别注意,如果要整合apache与Tomcat在一起,apache解析静态页,tomcat解析动态页,并且是同时配置多个虚拟站点,则要像如下这样配置
将
---------------------------
JkMount /*.jsp ajp13
# 把JSPX程序映射到Jk连接器上
JkMount /*.jspx ajp13
# 把servlet程序映射到Jk连接器上
JkMount /servlet/* ajp13
JkMount /*.servlet ajp13
-------------------------
分别如下形式加到具体的虚拟主机下
<VirtualHost *:8089>
ServerAdmin seal_bird21th@sohu.com
DocumentRoot d:/www/wabappone/ROOT
ServerName www.wabappone.com
ServerAlias wabappone
ErrorLog "logs/wabappone.localhost-error.log"
CustomLog "logs/wabappone.localhost-access.log" common
JkMount /*.jsp ajp13
# 把JSPX程序映射到Jk连接器上
JkMount /*.jspx ajp13
# 把servlet程序映射到Jk连接器上
JkMount /servlet/* ajp13
JkMount /*.servlet ajp13
</VirtualHost>
<VirtualHost *:8089>
ServerAdmin seal_bird21th@sohu.com
DocumentRoot d:/www/wabapptwo/ROOT
ServerName www.wabapptwo.com
ServerAlias wabapptwo
ErrorLog "logs/wabapptwo.localhost-error.log"
CustomLog "logs/wabapptwo.localhost-access.log" common
JkMount /*.jsp ajp13
# 把JSPX程序映射到Jk连接器上
JkMount /*.jspx ajp13
# 把servlet程序映射到Jk连接器上
JkMount /servlet/* ajp13
JkMount /*.servlet ajp13
</VirtualHost>
<VirtualHost *:8089>
ServerAdmin seal_bird21th@sohu.com
DocumentRoot d:/www/wabappthree/ROOT
ServerName www.wabappthree.com
ServerAlias wabappthree
ErrorLog "logs/wabappthree.localhost-error.log"
CustomLog "logs/wabappthree.localhost-access.log" common
JkMount /*.jsp ajp13
# 把JSPX程序映射到Jk连接器上
JkMount /*.jspx ajp13
# 把servlet程序映射到Jk连接器上
JkMount /servlet/* ajp13
JkMount /*.servlet ajp13
</VirtualHost>
=========================================
apache 与 tomcat在不同一台机器上的配置
apache 同时侦听多个端口
tomcat 同时侦听多个端口
apache 的Rewrite设置
如果,需要用到rewrite的html静态功能,请在httpd.conf文件中,找到
#LoadModule rewrite_module modules/mod_rewrite.so
取消掉前面的#注释,使mod_rewrite.so模块生效并且把所有的
AllowOverride None
更改为
AllowOverride All
===================================================
tomcat配置只允许特定的IP访问的配置方式
===================================================
在context.xml文件中加上如下代码
<Valve className="org.apache.catalina.valves.RemoteAddrValve(RemoteHostValve主机名)"
allow="127.0.0.1(允许访问的ip)" deny="192.168.1.1(拒绝访问的ip)"/>
org.apache.catalina.valves.RemoteAddrValve 过滤的是ip地址
org.apache.catalina.valves.RemoteHostValve 过滤的是主机名
如果存在多主机,多ip需要过滤,以","分隔.
http://127.0.0.1:81/WServiceServer/services/InvokeProduct