Apache2.2 一般在httpd.conf中打开 'LoadModule vhost_alias_module modules/mod_vhost_alias.so'
然后在httpd-vhosts.conf里配置虚拟主机,httpd-vhosts.conf的样例子如下
假设要配可以虚拟主机,支持三个域名
如 www.site1.com,www.site2.cn,china.site2.com,其中
1)www.site1.com是默认的,所有指到这台服务器IP的地址都会去运行这个VH
2)www.site2.cn,china.site2.com指向服务器上同一个静态物理目录,只是域名不同(这个在Apache里必须配置成2个虚拟主机,而不像IIS可以配置成1个虚拟主机,不同主机头)
-----
NameVirtualHost *:80 (表示 对所有的IP地址都在80端口启动虚拟主机,如果有不同IP,可以 NameVirtualHost 10.144.177.100:80,10.144.177.102:80等)
<VirtualHost *:80>
ServerAdmin webmaster@site1.com
DocumentRoot "E:/www/site1"
ServerName site1.com
ServerAlias www.site1.com
ErrorLog "logs/site1-error.log"
CustomLog "logs/site1-access.log" common
<Directory "E:/www/site1">
Options Indexes FollowSymLinks
DirectoryIndex index.html
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@site2.cn
DocumentRoot "E:/www/site2"
ServerName site2.cn
ServerAlias www.site2.cn
ErrorLog "logs/site2_error.log"
CustomLog "logs/site2_access.log" common
JkMount /search/* worker1
<Directory "E:/www/site2/">
Options Indexes FollowSymLinks
DirectoryIndex index.html
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@gdfsuez.cn
DocumentRoot "E:/www/site2"
ServerName china.site2.com
#ServerAlias china.site2.com
ErrorLog "logs/site2com_error.log"
CustomLog "logs/site2com_access.log" common
JkMount /search/* worker1
<Directory "E:/www/site2/">
Options Indexes FollowSymLinks
DirectoryIndex index.html
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>