本站的相关文章介绍过apache在基于IP配置虚拟机的方法,今天介绍一下基于主机名配置虚拟机的过程。
1. 把域名设置好,并且映射同一个IP,修改hosts:
192.168.1.20 www.good1.com
192.168.1.20 www.good2.com
192.168.1.20 www.good3.com
2. 把建立虚拟主机存放在网页的根目录内,
/www/goodt1/1.html
/www/good2/2.html
/www/good3/3.html
3. 将配置文件httpd-vhosts.conf放进httpd.conf中,并在httpd-vhosts.conf中写入如下配置:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName *
DocumentRoot /www/
</VirtualHost>
<VirtualHost *:80>
ServerName www.good1.com
DocumentRoot /www/good1/
<Directory "/www/good1">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.good2.com
DocumentRoot /www/good2/
<Directory "/www/good2">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.good3.com
DocumentRoot /www/good3/
<Directory "/www/good3">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
4. 配置完成,最后测试每个虚拟主机,分别访问wwwgood1.com、www.good2.com、www.good3.com.