Apache VirtualHost的用法


这么一个需求:同一台服务器上有两个应用,如
http://hostA:8080/serviceshttp://hostA:8080/admin
外部访问时,需要从不同的域名访问,如
http://services.host.comhttp://admin.host.com
一开始给他们这么一个比较简单的解决方案:
分别把services和admin两个应用,部署到不同的两个端口上,如
services -> http://hostA:8081/
admin -> http://hostA:8082/
接着在防火墙配两个公网IP,然后dns上把services.host.com和admin.host.com配置到这两个IP上。
当请求到达防火墙时,防火墙根据所访问的ip转发到hostA的对应端口上。
前 方用的防火墙是我们公司的Audemon 100,和公司的Audemon系统组的交流后得知,目前的防火墙版本不支持同时配置两个ip,要到六月底才能出版本支持。!@…%#%…%¥,晕倒,好 像这是很基本的功能来的吧,居然还不支持。没办法,此路不通。由于防火墙是不管域名的(因为域名资料是通过应用层传输的),那更别指望防火墙根据域名转发 了。
因此,我们只好提供了软件级的解决方案,让前方在Tomcat前加一个Apache 2.2,通过Apache的Virtual Host + AJP实现转发。
Apache的部分配置如下:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName host1.com
ProxyPass / ajp://host1.com:8009/
ProxyPassReverse / ajp://host1.com:8009/
</VirtualHost>
<VirtualHost *:80>
ServerName host2.com
ProxyPass / ajp://host2.com:8019/
ProxyPassReverse / ajp://host2.com:8019/
</VirtualHost>
Tomcat也需要配置AJP Connector,如host1.com的配置
<Connector port=”8009″ enableLookups=”false” redirectPort=”8443″ protocol=”AJP/1.3″ />
这个方案相对于防火墙的硬件方案,性能上要差一些,但还是不错的。
另 外还有一种方案是通过iptables的domain module来实现,但这个domain module好像是国内的某个高手写的,只更新到v0.02版本,并没有提交到iptables的标准里。虽然可以用而且性能比Apache的方案要高一 些,但是风险较大,而且配置麻烦(既要编译内核,又要配置iptables的rules),所以没有用这种方式。
本文来源于 冰山上的播客 http://xinsync.xju.edu.cn , 原文地址:http://xinsync.xju.edu.cn/index.php/archives/115

 

 

 

<Directory "/var/www/www">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/var/www/phorum">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

# 针对三部主机的 DocumentRoot 进行定!
<VirtualHost *:80>
    ServerName    linux.vbird.tsai
    DocumentRoot  /var/www/html
</VirtualHost>
<VirtualHost *:80>
    ServerName    www.vbird.tsai
    DocumentRoot  /var/www/www
    CustomLog     /var/log/httpd/www.access_log combined
    # 不同的主页可以指定不同的登录档资讯,这样比较好 debug 与分析啦!
</VirtualHost>
<VirtualHost *:80>
    ServerName    phorum.vbird.tsai
    DocumentRoot  /var/www/phorum
</VirtualHost>

 

 

<VirtualHost *>
ServerAdmin xxx@xxx.org
ServerName xxxxx
ProxyRequests Off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
# reverse proxy setting
ProxyPass / http://192.168.100.8:8180/
ProxyPassReverse / http://192.168.100.8:8180/
# cache dir root
CacheRoot "/var/www/proxy"
# max cache storage
CacheSize 50000000
# hour: every 4 hour
CacheGcInterval 4
# max page expire time: hour
CacheMaxExpire 240
# Expire time = (now - last_modified) * CacheLastModifiedFactor
CacheLastModifiedFactor 0.1
# defalt expire tag: hour
CacheDefaultExpire 1
# force complete after precent of content retrived: 60-90%
CacheForceCompletion 80

ErrorLog /var/log/apache2/error-westdc.geodata.cn.log
CustomLog /var/log/apache2/access-westdc.geodata.cn.log combined
ServerSignature On

</VirtualHost>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值