1.CentOS下httpd与tomcat整合
有时候需要在Web入口地址中隐藏非80端口,而最常见的方案是整合httpd和tomcat ,下面是通过mod_jk实现httpd和tomcat整合的详细流程,希望对大家有所帮助。
OS:CentOS6.6 i386
主要步骤:
1. 安装JDK
见 我的博客 jdk安装那篇
2. 安装httpd
[plain] view plaincopy
1. yum install httpd
2. /etc/init.d/httpd start
http://localhost 看到欢迎界面
#3. 安装tomcat (十分简单) 从原来的服务器拿过来
3.1官网下载apache-tomcat-7.0.42.tar.gz,解压缩
[plain] view plaincopy
1. tar �Cxzvf apache-tomcat-7.0.42.tar.gz
2. mv apache-tomcat-7.0.42/opt/tomcat7
3.2vim ~/bash_profile 添加:
[plain] view plaincopy
1. export TOMCAT_HOME=/opt/tomcat7
3.3开启tomcat服务
[plain] view plaincopy
1. $TOMCAT_HOME/bin/startup.sh
3.4http://localhost:8080 看到欢迎界面
4. 采用mod_jk方式整合httpd和tomcat
4.1安装httpd-devel
安装成功后,会有/usr/sbin/apxs服务,mod_jk的编译依赖于apxs
[plain] view plaincopy
1. yum install httpd-devel
4.2 安装mod_jk
apache网下载官tomcat-connectors-1.2.37-src.tar.gz 见目录
http://tomcat.apache.org/download-connectors.cgi
安装tomcat-connectors(mod_jk)
[plain] view plaincopy
1. tar �Cxzvf tomcat-connectors-1.2.37-src.tar.gz
2. mv tomcat-connectors-1.2.37-src /opt/mod_jk
3. cd /opt/mod_jk/native
4. ./configure --with-apxs=/usr/sbin/apxs --with-java-home=/opt/java
5. make
6. make install
复制mod_jk.so
[plain] view plaincopy
1. cp /opt/mod_jk/native/apache-2.0/mod_jk.so /usr/lib/httpd/modules/
路径根据实际情况
4.3修改httpd的配置
4.3.1 创建workers.properties
vim /etc/httpd/conf/workers.properties 添加以下内容:
1. # Defining a workernamed worker1 and of type ajp13
2. worker.list=worker1
3. # Set properties forworker1
4. worker.worker1.type=ajp13
5. worker.worker1.host=localhost
6. worker.worker1.port=8009
7. worker.worker1.lbfactor=50
8. worker.worker1.cachesize=10
9. worker.worker1.cache_timeout=600
10.worker.worker1.socket_keepalive=1
11.worker.worker1.socket_timeout=300
4.3.2 创建mod_jk.conf
vim /etc/httpd/conf/mod_jk.conf 添加以下内容:
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk logs
JkLogFile /etc/httpd/logs/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 tosend SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat setthe request format
JkRequestLogFormat "%w %V %T"
JkMount /servlet/* worker1
JkMount /*.jsp worker1
JkMount /*.do worker1
原文:
1. JkWorkersFile /etc/httpd/conf/workers.properties
2. # Where to put jk logs
3. JkLogFile /etc/httpd/logs/mod_jk.log
4. # Set the jk log level[debug/error/info]
5. JkLogLevel info
6. # Select the log format
7. JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
8. # JkOptions indicate tosend SSL KEY SIZE,
9. JkOptions +ForwardKeySize +ForwardURICompat-ForwardDirectories
10.# JkRequestLogFormat setthe request format
11.JkRequestLogFormat "%w %V %T"
12.# 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理
13.JkMount /servlet/* worker1
14.JkMount /*.jsp worker1
4.3.3 修改httpd.conf
vim httpd.conf 修改以下内容
[html] view plaincopy
1. ServerName修改为:ServerName 10.11.18.45:80
2. DirectoryIndex 行添加 index.jsp index.htm
添加以下内容,其中”/var/wwwroot”是你要发布的Web项目所在的父目录
[plain] view plaincopy
1. DocumentRoot"/var/wwwroot"
2. <Directory"/var/wwwroot">
3. Options Includes FollowSymLinks
4. AllowOverride None
5. Order deny,allow
6. Allow from all
7. XBitHack on
8. </Directory>
9. <Directory"/var/wwwroot/WEB-INF">
10. Order deny,allow
11. Deny from all
12.</Directory>
以下内容:添加
[plain] view plaincopy
1. LoadModule jk_module/usr/lib64/httpd/modules/mod_jk.so
2. Include/etc/httpd/conf/mod_jk.conf
4.3.4 修改tomcat的配置
vim$TOMCAT_HOME/conf/server.xml
[plain] view plaincopy
1. 将 <Server …>部分 修改为
2. <Hostname="localhost" appBase="/var/wwwroot"
3. unpackWARs="true"autoDeploy="true">
4.3.5 restart httpd 和 tomcat
[plain] view plaincopy
1. /etc/init.d/httpd restart
2. $TOMCAT_HOME/bin/shutdown.sh
3. $TOMCAT_HOME/bin/startup.sh
4.3.6 测试
在/var/wwwroot目录下新建目录myproject,myproject下新建index.jsp
[html] view plaincopy
1. <%@ page language="java" import="java.util.*"pageEncoding="ISO-8859-1"%>
2. <%
3. String path = request.getContextPath();
4. String basePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5. %>
6. <!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
7. <html>
8. <head>
9. <basehrefbasehref="<%=basePath%>">
10. <title>My JSP 'index.jsp' startingpage</title>
11. <meta http-equiv="pragma"content="no-cache">
12. <metahttp-equivmetahttp-equiv="cache-control" content="no-cache">
13. <meta http-equiv="expires"content="0">
14. <metahttp-equivmetahttp-equiv="keywords" content="keyword1,keyword2,keyword3">
15. <metahttp-equivmetahttp-equiv="description" content="This is my page">
16. <!--
17. <link rel="stylesheet"type="text/css" href="styles.css">
18. -->
19. </head>
20. <body>
21. Hello, I am mango_song ,this is my JSPpage. <br>
22. </body>
23.</html>
http://localhost/myproject 看到相应界面,至此httpdtomcat已经整合成功
2.虚拟主机配置
#</VirtualHost>
<VirtualHost IP地址:80>
ServerName www.abc.com
ServerAdmin webmaster@localhost
DocumentRoot "/home/web/tomcat/目录"
ErrorLog "/var/log/httpd/wwwerror.log"
CustomLog "/var/log/httpd/www.log" common
#JkMountCopy On
</VirtualHost>
http://blog.csdn.net/mango_song/article/details/10016529?utm_source=tuicool