apache与tomcat整合共用80端口(ajp与http proxy)

apache与tomcat整合共用80端口(ajp与http proxy)

配置:httpd.conf
 
 # Virtual hosts
 #这个#去掉,使其启动;
 Include conf/extra/httpd-vhosts.conf   
 
 #使用ajp做代理
 LoadModule proxy_module modules/mod_proxy.so
 LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
 #若使用http代理,还需要以下
 LoadModule proxy_connect_module modules/mod_proxy_connect.so
 LoadModule proxy_http_module modules/mod_proxy_http.so
 LoadModule proxy_balancer_module modules/mod_proxy_balancer.so 
 LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
 
 
 配置:httpd-vhosts.conf,注意,以下两种方式测试只能二选一
 
 #以下是使用ajp_proxy,这里的8010端口需要与tomcat的ajp端口一致
  <VirtualHost *:80> 
  ServerAdmin localhost 
  ProxyPass /jsp ajp://localhost:8009/
  ProxyPassReverse /jsp ajp://localhost:8009/
  ServerName localhost 
  ErrorLog logs/localhost-error_log 
  CustomLog logs/localhost-access_log common 
 </VirtualHost>

 #以下是http_proxy
 <VirtualHost *>
  ServerName localhost
  #负载均衡
  ProxyPass / balancer://test/
  <Proxy balancer://test/>
   BalancerMember http://localhost:8090/
   BalancerMember http://11.50.70.55:8090/
  </Proxy> 
 </VirtualHost>
 
3、tomcat:
  配置:server.xml
  <!--修改ajp_proxy端口,以便使用ajp代理-->
   <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
   
  <!--修改http_proxy端口,以便使用http代理--> 
   <Connector port="8090" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />