转--DocumentRoot 关系 与 Apache vhost 配置关系

  • 转载自 http://www.jianshu.com/p/fd3e6112d578
  • 安装

安装完成 Wampserver 3.0.6,修改 DocumentRoot。

  • 修改 DocumentRoot
    修改服务器根目录路径:/wampserver_intall_dir/to/bin/apache/.../conf/httpd.conf

搜索 “DocumentRoot”,将当前行与下一行的目录路径,都修改为指定的根目录路径。

重启,http://localhost 发现返回相应没有改变。

  • 测试
    用一个错误的路径“D:\htdocs\”测试,发现 Wampserver 重启后,出现服务状态不正常。这说明配置文件肯定是修改对了。

右键点击,使用 Wampserver 工具 "Check httpd.conf syntax",提示 DocumentRoot must be a directory。Windows 中,使用右斜线()表示路径,结尾处不能带有 \ 。如果使用左斜线(/),结尾处可带上左斜线(/),也可以不需要。

确认修改的配置文件是正确的,为什么不生效呢?检查发现,apache 指定了一个 virtualhost:

<VirtualHost *:80>
ServerName localhost
DocumentRoot D:/wamp/wamp64/www
<Directory "D:/wamp/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

注释 httpd-vhosts.conf 文件中 vhost 配置,重启 Wampserver,刷新页面就正常了。

  • Conclude
    httpd-vhosts.conf 文件中,为某个 ServerName 指定的 DocumentRoot 是获得最高优先级的,而不会使用 httpd.conf 中所指定的。

  • 去掉 VirtualHost 配置中的 DocumentRoot 与 Directory

    DocumentRoot D:/wamp/wamp64/www

    <Directory "D:/wamp/wamp64/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
    </Directory>

    扫描二维码关注公众号,回复: 356010 查看本文章

请求 "http://localhost",发现 httpd.conf 中使用 DocumentRoot 的生效了。

猜你喜欢

转载自4636.iteye.com/blog/2383002