Author of this content has low reputation.
我们在本地搭建网站,一般都是通过http://localhost/news.html这样的格式来访问。如果要通过更好的url地址如 www.tiantian.com这样的地址来访问,或者本地要搭建多个网站,那么,这时虚拟主机的配置就要派上用场了。本文的本地服务器为apache。
本地虚拟主机的配置只需三步:
1. 启用 httpd-vhosts.conf
在 httpd.conf 文件中
# Virtual hosts ,虚拟主机 Include conf/extra/httpd-vhosts.conf
2. 在httpd-vhosts.conf文件中做配置(文件位置: conf/extra/httpd-vhosts.conf)
#配置我们自己的虚拟主机
<VirtualHost 127.0.0.1:80> DocumentRoot "d:/myblog" #这里配置欢迎首页面 DirectoryIndex index.html index.htm index.php <Directory /> Options FollowSymLinks #不许可别人修改我们的页面 AllowOverride None #设置访问权限 Order allow,deny Allow from all </Directory> </VirtualHost>
3. 修改hosts 文件,在hosts文件中添加我们的ip 和主机映射关系
hosts 文件位置 c:/windows/system32/drivers/etc/hosts 127.0.0.1 www.tiantian.com
.jpg)