1、首先在本地配好环境[wamp];
2、打开C:\Windows\System32\Drivers\etc这个目录下的hosts 文件进行编辑:
127.0.0.1 test.com
127.0.0.1 kpf.com
127.0.0.1xxx.com[这里可以随意写成其他的域名]
3、打开D:\wamp\bin\apache\apache2.2.8\conf这个目录下的httpd.conf找到407行左右:Include conf/extra/httpd-vhosts.conf 把前面的#去掉[切记:一定要去掉#号]
找到Directory
找到DocumentRoot
【在此之前一定要在D盘新建一个work文件,这里是放站点的文件路径,可以随意变动名称和路径。】
4、打开D:\wamp\bin\apache\apache2.2.8\conf\extra这个目录下的httpd-vhosts.conf这个文件:
复制相同的代码进行更改:
<VirtualHost *:80>
DocumentRoot "D:\work\test"
ServerName kpf.com
ServerAlias *.kpf.com
DirectoryIndex index.html index.htm index.php
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:\work\test1"
ServerName test.com
ServerAlias *.test.com
DirectoryIndex index.php index.html index.htm
</VirtualHost>
如图所示:
最后重启apache,访问站点;OK!
知识扩展:
1、Windows下访问主页报403错误!
在(httpd-vhosts.conf 中进行配置)示例代码:
<VirtualHost 10.32.0.231:80>
ServerAdmin you@example.com
DocumentRoot /26xmu/EtbTz/EtbTz/
ServerName www.etongbao.org
ErrorLog /usr/local/apache/logs/erroretbtz_log
CustomLog /usr/local/apache/logs/accessetbtz_log common
<Directory "/26xmu/EtbTz/EtbTz">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
图示:
参考资料:http://bbs.chinaunix.net/thread-3758032-1-1.html
参考资料:http://hi.baidu.com/buttonfly/item/dd1a3dc336508a2f46d5c0b0
2、访问主页直接显示目录!
去掉其中的indexes即可。
参考资料:http://blog.sina.com.cn/s/blog_a03d702f0101133h.html
3、访问主页404错误!
原因1:访问的目录确实不存在!
原因2:服务器默认打开的主页文档类型项目根目录当中没有,打开D:\wamp\bin\apache\apache2.2.8\conf这个目录下的httpd.conf 找到DirectoryIndex 加上默认值
如图所示:
联系客服