centos 下整合apache+tomcat7 手记及简单排错


安装TOMCAT7过程不再赘述,此处仅记录安装Apache以及Apache整合TOMCAT7过程

 

第一步:下载相关文件

a)    Apache源码  http://apache.dataguru.cn//httpd/httpd-2.4.3.tar.gz

b)    jk_mod1.2.x二进制包:

http://www.fayea.com/apache-mirror//tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz

 

第二步:安装apache

a)tar xzvf httpd-2.4.3.tar.gz

b)cd httpd-2.4.3

c)./configure --prefix= /maple/program/apache --enable-so,此处如果报错(

APR not found. Please read the documentation 解决方法参加注释1

APR-util not found.  Please read the documentation.   解决方法参加注释2

   修正后安装命令如下:

./configure --prefix=/maple/program/apache --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/

d)make

e)make install


第三步:编译生成mod_jk

a)tar xzvf tomcat-connectors-1.2.37-src.tar.gz

b)cd  tomcat-connectors-1.2.37-src/native

c)./configure --with-apxs=/maple/program/apache/bin/apxs

d)make

e)cp ./apache-2.0/mod_jk.so /maple/program/apache/modules/

配置:

1)cd /maple/program/apache/modules

   vi workers.properties

   

worker.list = loadbalancer,tomcat2,tomcat3,tomcat4,tomcat1,tomcat5,tomcat6  #server 列表

 

 

#========controller,负载均衡控制器========

worker.loadbalancer.type=lb     # load-balance worker, can be "lb, status"

worker.loadbalancer.method=B    # 如何选择最优的worker, B[usyness]: 选最不忙的, R[equest]:

worker.loadbalancer.balance_workers=tomcat4,tomcat5       # 指定分担请求的tomcat

worker.loadbalancer.sticky_session=1 # 1: True, otherwise False, 相同session id一直访问同一服务器

#worker.loadbalancer.sticky_session_force=true # session id出错状态不返回500, 由另一worker接手

 

 

 

#========tomcat1========

worker.tomcat1.port=8051       #ajp13 端口号,在tomcatserver.xml配置,

worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat1.type=ajp13

worker.tomcat1.lbfactor = 1   #server的加权比重,值越高,分得的请求越多

#worker.tomcat1.cachesize=10

#worker.tomcat1.cache_timeout=600

worker.tomcat1.socket_keepalive=1

worker.tomcat1.socket_timeout=300

worker.tomcat1.recovery_options=3

 

#========tomcat2========

worker.tomcat2.port=8052         #ajp13 端口号,在tomcatserver.xml  ,默认8009

worker.tomcat2.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat2.type=ajp13

worker.tomcat2.lbfactor = 1   #server的加权比重,值越高,分得的请求越多

#worker.tomcat2.cachesize=10

#worker.tomcat2.cache_timeout=600

worker.tomcat2.socket_keepalive=1

worker.tomcat2.socket_timeout=300

worker.tomcat2.recovery_options=3

 

 

#========tomcat3========

worker.tomcat3.port=8053         #ajp13 端口号,在tomcatserver.xml  ,默认8009

worker.tomcat3.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat3.type=ajp13

worker.tomcat3.lbfactor = 1   #server的加权比重,值越高,分得的请求越多

#worker.tomcat3.cachesize=10

#worker.tomcat3.cache_timeout=600

worker.tomcat3.socket_keepalive=1

worker.tomcat3.socket_timeout=300

worker.tomcat3.recovery_options=3

 

 

#========tomcat4========

worker.tomcat4.port=8054       #ajp13 端口号,在tomcatserver.xml配置,

worker.tomcat4.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat4.type=ajp13

worker.tomcat4.lbfactor = 1   #server的加权比重,值越高,分得的请求越多

#worker.tomcat4.cachesize=10

#worker.tomcat4.cache_timeout=600

worker.tomcat4.socket_keepalive=1

worker.tomcat4.socket_timeout=300

worker.tomcat4.recovery_options=3

 

#========tomcat5========

worker.tomcat5.port=8055       #ajp13 端口号,在tomcatserver.xml配置,

worker.tomcat5.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat5.type=ajp13

worker.tomcat5.lbfactor = 1   #server的加权比重,值越高,分得的请求越多

#worker.tomcat5.cachesize=10

#worker.tomcat5.cache_timeout=600

worker.tomcat5.socket_keepalive=1

worker.tomcat5.socket_timeout=300

worker.tomcat5.recovery_options=3

 

#========tomcat6========

worker.tomcat6.port=8056       #ajp13 端口号,在tomcatserver.xml配置,

worker.tomcat6.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址

worker.tomcat6.type=ajp13

worker.tomcat6.lbfactor = 1   #server的加权比重,值越高,分得的请求越多

#worker.tomcat6.cachesize=10

#worker.tomcat6.cache_timeout=600

worker.tomcat6.socket_keepalive=1

worker.tomcat6.socket_timeout=300

worker.tomcat6.recovery_options=3

2)cd /maple/program/apache/conf

   vi  mod_jk.conf

   #TOMCAT整合开始

LoadModule jk_module modules/mod_jk.so

JkWorkersFile modules/workers.properties

 

JkMount /*.jsp loadbalancer

JkMount /*.action loadbalancer

JkMount /*Servlet loadbalancer

JkMount /WEB-INF/* loadbalancer

 

JkOptions +ForwardKeySize +ForwardURICompat +FlushHeader +DisableReuse

 

#TOMCAT整合结束

 

HostnameLookups Off

3)修改httpd.conf 在最末尾加入include conf/mod_jk.conf

 

4)Apache启动命令;

apachectl start

apachectl stop

apachectl restart

注释1

wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz

tar -zxf apr-1.4.5.tar.gz

cd  apr-1.4.5

./configure --prefix=/usr/local/apr

make && make install

注释2

wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz

tar -zxf apr-util-1.3.12.tar.gz

cd apr-util-1.3.12

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 

make && make install


常见问题及解决办法

1)403

  解决办法,找到apache安装目录下的http.conf ,找到DirectoryIndex index.html  后添加index.jsp

  即    DirectoryIndex index.html index.jsp

  然后搜索Deny from all 更改为:Allow from all

<Directory />

  Options Indexes FollowSymLinks Includes

  AllowOverride None

  Order allow,deny

  Allow from all

  Satisfy all

</Directory>

2)引用不好用,例如<!--#include virtual="/menu/top.htm"-->无法正常引入文件

找到如下地方

# AddType text/html .shtml

# AddOutputFilter INCLUDES .shtml

 

修改为

AddType text/html .htm .html .shtm

AddOutputFilter INCLUDES .htm .html .shtm

 

并且找到

Options Indexes FollowSymLinks

修改为:Options Indexes FollowSymLinks Includes


3)页面出现乱码

   <Connector port="8051" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>

   找到tomcat配置文件,添加URIEncoding="UTF-8"重启即可。

  

4)开启Rewrite功能

  在conf目录下httpd.conf中找到
LoadModule rewrite_module modules/mod_rewrite.so

update 20130506===============================================

url_rewrite功能在windows与linux略有不同,如果windows下好用,但是linux不好用,如伪静态,请尝试修改正则表达式即可

5)

禁止访问敏感目录及源码泄露

<FilesMatch ".JSP">

Order allow,deny

Deny from all

</FilesMatch>

 

<Directory ~ "/WEB-INF/">

Order allow,deny

Deny from all

</Directory>

你可能感兴趣的:(apache,tomcat7,403)