官方文档:
1.准备
主包:
httpd-2.4.17.tar.gz
依赖:
apr-1.5.2.tar.gz,
apr-util-1.5.4.tar.gz,
pcre-8.37.tar.gz,
配置apache与tomcat集成时用:
tomcat-connectors-1.2.41-src
2. 将上述包上传到服务器(我把它们放在/var/public_root下,准备把http服务安装在/opt下)
2.1 解压pcre
# tar jxvf pcre-8.37.tar.gz 2.2 解压httpd # tar jxvf httpd-2.4.16.tar.gz 2.3 将apr与apr-util解压到httpd-2.4.17/srclib目录下 # tar jxvf apr-1.5.2.tar.bz2 -C httpd-2.4.17/srclib # tar jxvf apr-util-1.5.4.tar.bz2 -C httpd-2.4.17/srclib 2.4 将apr-1.5.2和apr-util-1.5.4分别改名为apr和apr-util # cd /var/public_root/httpd-2.4.17/srclib/ # mv apr-1.5.2 apr # mv apr-util-1.5.4 apr-util 3. 安装依赖包 安装位置: /opt/软件名 apr与apr-util不需要单独安装,只需要在安装httpd的时候指定一下 3.1 安装pcre # cd /var/public_root/pcre-8.37 # make & make install 编译并安装 # make clean 清楚make产生的垃圾 4. 安装httpd # cd /var/public_root/httpd-2.4.17 # ./configure --prefix=/usr/local/apache -with-pcre=/usr/local/pcre-8.37/bin/pcre-config -with-included-apr # make & make install # make clean 5. 配置httpd.conf 编辑/usr/local/apache/conf/httpd.conf Listen值改为9080 ServerName值改为localhost:9080 6. 启动 # cd /opt/apache/bin/ # ./apachectl -k start
7. 在浏览器里输入localhost:9080看到It Works! 就表示成功了。
8. apache与tomcat集成
8.1 在/opt/httpd-2.4.17/conf新建3个文件: mod_jk.conf,workers.properties和uriworkermap.properties.
mod_jk.conf
JkWorkersFile conf/workers.properties JkMountFile conf/uriworkermap.properties # Where to put jk logs JkLogFile 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 to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T" # 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理 JkMount /*.htm worker1 # 将所有以*.htm的结尾请求交给worker1处理,我这里的*.htm与*.html请求不同,*.htm是动态请求,需要tomcat处理 JkMount /*.jsp worker1 # 将所有以*.htm的结尾请求交给worker1处理, JkMount /servlet/* worker1uriworkmap.properties
#将所有请求交给worker1处理
/*=worker1 !/*.gif=worker1 !/*.jpg=worker1 !/*.png=worker1 !/*.css=worker1 !/*.js=worker1 !/*.html=worker1workers.properties
# Defining a worker named worker1 and of type ajp13
worker.list=worker1 #Set properties for worker1 worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 worker.worker1.lbfactor=18.2 修改httpd.conf
在最后面添加 LoadModule jk_module modules/mod_jk.so Include /opt/httpd-2.4.17/conf/mod_jk.conf8.3 修改/opt/conf/server.xml字段
找到
<!-- You should set jvmRoute to support load-balancing via AJP ie : <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> --> <Engine name="Catalina" defaultHost="localhost">修改为
也就是加了个 jvmRoute="worker1",这个worker1一定要与workers.properties中对应。
8.4 注意
httpd 服务的DocumentRoot一定要与tomcat的docBase相同,之前就是因为不同,访问主页一直都是返回It Worked!
我tomcat的docBase是"/project/dld",所以DocumentRoot也要是"/project/dld", 修改成下面这个样子
8.5 重起tomcat与httpd服务
# cd /opt/apache-tomcat-7.0.42/bin # ./shutdown.sh # ./startup.sh # cd /opt/httpd-2.4.17/bin # ./apachectl restart在浏览器里输入localhost应该可以直接看到主页了