日期:2014-05-16  浏览次数:21070 次

Apache 配置虚拟主机

Apache 配置虚拟主机。

需求目的:在本机浏览器中键入地址,比如:http://www.sina.com 就能访问您电脑中的目录文件。

下面是配置步骤:

1、先在 Apache 的安装目录中打开 conf/httpd.conf,使用编辑器搜索“Virtual hosts”,会找到如下代码:

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf  #去掉这行前面的 # 号

去掉上面的#号,表示:载入虚拟主机的配置文件

2、Apache 安装目录, conf/extra/ 下找到 httpd-vhosts.conf,打开添加如下代码:

# 配置虚拟主机
<VirtualHost 127.0.0.1:80>
    #设置访问本机地址
    DocumentRoot "D:/web"
    #配置缺省页面
    DirectoryIndex index.shtml index.html index.htm index.php
    <Directory />
        Options FollowSymLinks
	#不允许别人修改页面
	AllowOverride none
	#设置访问权限
	Order allow,deny
	Allow from all
    </Directory>
</VirtualHost>

保存关闭!

3、找到 C:\WINDOWS\system32\drivers\etc\hosts,具体的系统盘符按实际而定。

打开 hosts 文件,在后面追加代码:

127.0.0.1       www.sina.com

这样就完成虚拟主机的配置了。