Tomcat连接Apache之mod_proxy模块

编译安装Apache
安装apr和apr-tuil
httpd-2.4.10需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。以下是采用前者进行安装:
yum -y install gcc gcc-c++ expat-devel pcre-devel zlib zlib-devel openssl openssl-devel
cd /tools/
tar xf apr-1.6.3.tar.gz
tar xf apr-util-1.6.1.tar.gz
cd /tools/apr-1.6.3
./configure --prefix=/usr/local/apr
make && make install

cd /tools/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

安装Apache
tar xf /tools/httpd-2.4.10.tar.gz
cp -r /tools/apr-1.6.3 /tools/httpd-2.4.10/srclib/apr
cp -r /tools/apr-util-1.6.1 /tools/httpd-2.4.10/srclib/apr-util
cd /tools/httpd-2.4.10

./configure --prefix=/application/apache2.4.10 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=worker --enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-lbmethod-heartbeat --enable-heartbeat --enable-slotmem-shm --enable-slotmem-plain --enable-watchdog --with-included-apr

make
make install

启动Apache
vim /application/apache2.4.10/conf/httpd.conf #把这两个模块注释打开
129 LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
130 LoadModule slotmem_plain_module modules/mod_slotmem_plain.so
修改配置文件后检查语法并启动
/application/apache/bin/apachectl -t
/application/apache/bin/apachectl graceful

cp /application/apache/bin/httpd /etc/init.d/httpd
/etc/init.d/httpd -k start

lsof -i :80

配置apache通过mod_proxy模块与Tomcat连接
httpd IP 10.125.192.5
要使用mod_proxy与Tomcat实例连接,需要apache已经装载mod_proxy、mod_proxy_http、mod_proxy_ajp和proxy_balancer_module(实现Tomcat集群时用到)等模块:

/application/apache/bin/httpd -D DUMP_MODULES|grep proxy proxy_module (shared)
proxy_connect_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_fcgi_module (shared)
proxy_scgi_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_express_module (shared)

编辑apache配置文件
cp /application/apache/conf/httpd.conf /application/apache/conf/httpd.conf.bak
mkdir -p /application/apache/conf/extra #创建保存配置文件目录 优化配置文件
Include /application/apache/conf/extra/httpd-proxy.conf #最后一行添加
vim /application/apache/conf/extra/httpd-proxy.conf


 ProxyVia On
 ProxyRequests Off
 ProxyPass / http://10.125.192.2:8080/
 ProxyPassReverse / http://10.125.192.2:8080/
 
   Require all granted
 
 
   Require all granted
 

/application/apache/bin/apachectl -t #检查语法
重启Apache测试

测试访问
10.125.192.5
Tomcat连接Apache之mod_proxy模块_第1张图片

你可能感兴趣的:(Tomcat)