在本地Apache服务器配置虚拟主机站点

Apache 配置localhost虚拟主机步骤
1,打开apache目录下httpd.conf文件,找到如下模块
        # Virtual hosts
        #Include conf/extra/httpd-vhosts.conf
去掉前面的#,这样就开启了httpd-vhosts虚拟主机文件,这时httpd.conf中的documentRoot不在起作用,需要在httpd- vhosts.conf重新配置。

2,打开conf/extra/httpd-vhosts文件,配置好localhost虚拟主机,参照httpd- vhosts文件中实例,修改成如下:
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.lin3615
    DocumentRoot "D:/phpweb/apache/docs/dummy-host2.lin3615"
    ServerName localhost

    ServerAlias localhost
    ErrorLog "logs/dummy-host2.lin3615-error.log"
    CustomLog "logs/dummy-host2.lin3615-access.log" common
</VirtualHost>
修改配置如下:
DocumentRoot 修改为本地apache的www目录
ServerName改为localhost
3,重启Apache,发现localhost可以正常打开,配置localhost比较简单

实例:Apache配置 www.myweb.com 虚拟主机步骤

1,方法同上,复制配置代码修改如下:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "D:/phpweb/apache/htdocs"
    ServerName www.myweb.com
    ServerAlias www.myweb.com
    ErrorLog "logs/dummy-host.lin3615-error.log"
    CustomLog "logs/dummy-host.lin3615-access.log" common
</VirtualHost>

2,打开host文件(C:/WINDOWS/system32/drivers/etc/hosts),增加一行代码
127.0.0.1      www.myweb.com

3,在浏览器中打开www.myweb.com,如果发现如下错误403 Forbidden错误
Forbidden You don't have permission to access / on this server.
分析:这主要是目录访问权限没有设置,需要设置对目录的访问权!

4,打开httpd.conf文件,找到如下语句
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>

把 Deny from all 修改为 allow from all

posted @ 2014-03-17 22:18  好记性还真不如烂笔头  阅读(357)  评论(0编辑  收藏  举报