1.记事本打开hosts文件,文件在:C:\ Windows\ System32\ drivers\etc 文件夹下, 在文件内容的末尾写入:
1 127.0.0.1(不可改) www.test.com(自定义)
2.记事本打开httpd.conf文件 ,该文件在apache的目录下,如: D:\AppServ\Apache2.2\conf,修改如下两处:
1 LoadModule vhost_alias_module modules/mod_vhost_alias.so //去掉前面的#,意思是启用apache的虚拟主机功能
3.记事本打开httpd-vhosts.conf文件,该文件在apache的目录下,如:D:\AppServ\ Apache2.2\conf\extra,按照文件中原有的格式再添加一个VirtualHost,只修改下面有注释的两处,如下:
1 <VirtualHost *:80> 2 ServerAdmin webmaster@dummy-host2.example.com 3 DocumentRoot "/htdocs/www" //DocumentRoot后面修改为网站的根路径 4 ServerName www.test.com //ServerName后面修改为hosts中设置的域名 5 ErrorLog "logs/dummy-host2.example.com-error.log 6 CustomLog "logs/dummy-host2.example.com-access.log" common 7 </VirtualHost>
4.重启apache,地址栏访问www.test.com即可.