apache+tomcat配置动态二级域名

 

apache2.2配置

 

编译要求支持的组件:

 

LoadModule proxy_module modules/mod_proxy.so
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 alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
 

 

编辑主配置文件:conf/httpd.conf,再文件结尾加入:

 

 

ProxyRequests Off
ProxyPreserveHost on
 

 

打开虚拟主机配置的Include

 

 

#Include conf/extra/httpd-vhosts.conf

 修改为:

 

Include conf/extra/httpd-vhosts.conf
 

 

编辑虚拟主机配置文件 vi conf/extra/http-vhost.conf

 

 

 1.默认虚拟主机,使用ip或任意域名访问

 

 

# default host configuration for business and rm
<VirtualHost *:80>
  ErrorLog "logs/error_default.log"
  LogLevel warn
  CustomLog "logs/access_default.log" combinedio

  ProxyPass / balancer://cluster-busi/ stickysession=jsessionid nofailover=Off
  ProxyPassReverse / balancer://cluster-busi/
  # business ab+lb, Horizontal expansion of multiple business nodes
  <Proxy balancer://cluster-busi>
    BalancerMember  http://10.10.10.181:8013 loadfactor=5 retry=10
    BalancerMember  http://10.10.10.182:8013 loadfactor=5 retry=10
    ProxySet lbmethod=bybusyness
  </Proxy>
</VirtualHost>
 

 

2.域名访问

 

   支持: http://www.domain.com 和http://username.domain.com

   对于二级域名:http://username.domain.com先使用rewrite重写为:http://username.domain.com/username/,然后再使用proxy转发到下层的tomcat集群处理

 

<VirtualHost *:80>  
  ServerName s3.amazonaws.com
  ServerAlias *.s3.amazonaws.com
  
  ErrorLog "logs/error_s3.log"  
  LogLevel warn
  CustomLog "logs/access_s3.log" combinedio  
  
  RewriteEngine on  
  RewriteLog "logs/rewrite_s3.log"  
  RewriteLogLevel 3
  RewriteCond %{HTTP_HOST} !^s3\.amazonaws\.com$
  RewriteCond %{HTTP_HOST} ^.+\.s3\.amazonaws\.com$
  RewriteRule /(.*) /%{HTTP_HOST}/$1  
  RewriteRule /(.+)\.s3\.amazonaws\.com/(.*)$ /$1/$2 [PT]
  
	ProxyPass / balancer://cluster-s3/ nofailover=Off  
  ProxyPassReverse / balancer://cluster-s3/  
  <Proxy balancer://cluster-s3>  
    BalancerMember  http://localhost:8080/awsintf	 loadfactor=1 retry=10  
    BalancerMember  http://10.10.10.182:8013/oss loadfactor=5 retry=10  
    ProxySet lbmethod=byrequests  
  </Proxy>
</VirtualHost>
 

 

tomcat集群配置略。

 

你可能感兴趣的:(apache)