1:
apr安装:
./configure --prefix=/usr/local/apache/apr && make && make install
apr-util安装:
./configure --with-apr=/usr/local/apache/apr/bin/apr-1-config --prefix=/usr/local/apache/apr-util && make && make install
httpd安装:
./configure --with-apr=/usr/local/apache/apr/bin/apr-1-config --with-apr-util=/usr/local/apache/apr-util/bin/apu-1-config --enable-so --enable-proxy --enable-proxy-ajp --enable-proxy-http --prefix=/usr/local/apache
make
make install即可安装
在配置文件里面确认:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
被加载
2:安装tomcat
解压安装即可:我将tomcat放到了
##需要修改的部分
resourceName="UserDatabase"/>
在/usr/vhome/a/b/c/abc.com/www/hello下有index.php文件,内容如下:
3:httpd配置:
将httpd.conf中的
#Include conf/extra/httpd-vhosts.conf 中的注释去掉
在/usr/local/apache/conf/extra/http-vhosts.conf中加入如下内容:
ServerName
ProxyRequests Off
ProxyPreserveHost On
ErrorLog /var/log/httpd/tomcat.error.log
CustomLog /var/log/httpd/tomcat.log combined
Order deny,allow
Allow from all
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
然后重启httpd服务!
4:测试,现在在windows下做本地解析,在C:\Windows\System32\drivers\etc\hosts中加入:
192.168.2.222
通过浏览器测试:
另外如果想用域名的别名访问:在需要在/usr/local/apache/conf/extra/http-vhosts.conf中的
ServerName 下添加一行:
ServerAlias 然后/usr/local/apache/bin/apachectl -k graceful 重启该服务,同时在tomcat的server.xml中也需要添加
一个别名;添加如下;
......
##需要添加的内容
则通过也可以访问的,如附件:
在配置过程中遇到两个问题:
1:
[root@haproxy2 logs]# cat error_log
[Mon Apr 28 15:00:32.353558 2014] [proxy_balancer:emerg] [pid 30843:tid 3078502080] AH01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded??
[Mon Apr 28 15:00:32.353960 2014] [:emerg] [pid 30843:tid 3078502080] AH00020: Configuration Failed, exiting
[root@haproxy2 logs]#
解决方法:
在httpd.conf中将#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so 前的注释给去掉!
2:
[root@haproxy2 extra]# /usr/local/apache/bin/apachectl start
AH00112: Warning: DocumentRoot [/usr/local/apache/docs/dummy-host.example.com] does not exist
AH00112: Warning: DocumentRoot [/usr/local/apache/docs/dummy-host2.example.com] does not exist
AH00112: Warning: DocumentRoot [/usr/local/apache/docs/dummy-host2.example.com] does not exist
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
(2)No such file or directory: AH02291: Cannot access directory '/var/log/httpd/' for error log of vhost defined at /usr/local/apache/conf/extra/httpd-vhosts.conf:52
AH00014: Configuration check failed
解决方法:
mkdir -p /var/log/httpd
如果要使用mod_proxy_http方式,则需要修改如下;
ServerName
ServerAlias
ProxyRequests Off
ProxyPreserveHost On
ErrorLog /var/log/httpd/tomcat.error.log
CustomLog /var/log/httpd/tomcat.log combined
Order deny,allow
Allow from all
ProxyPass / ##修改ajp协议为http协议,修改8009端口为8080端口
ProxyPassReverse / ##修改ajp协议为http协议,修改8009端口为8080端口
tomcat不需要任何的修改,即可访问!
如果后面有几个tomcat,则可这样设置:
摘之:
Balancers may also be used:
Balancer Reverse Proxy
BalancerMember ajp://app1.example.com:8009 loadfactor=1
BalancerMember ajp://app2.example.com:8009 loadfactor=2
ProxySet lbmethod=bytraffic
ProxyPass /app balancer://cluster/app
阅读(3281) | 评论(0) | 转发(0) |