设置 Apache 文件根目录 和 设置Apache 虚拟目录(Virtual Directory)

来源:互联网 发布:八爪鱼软件 编辑:程序博客网 时间:2024/06/04 23:24

设置 Apache 文件根目录 

该章节讲述如何设置 Apache HTTP Server 的文件根目录(DocumentRoot) 。

在安装 Apache 时,系统会给定一个缺省的文件根目录。

如果你觉得将网页存在这个缺省目录不方便,觉得应该另外设个目录作为 Apache 文件根目录,你可以修改 Apache 的配置文件 httpd.conf 里有关文件根目录的设置。

Apache HTTP Server 的缺省文件根目录 (DocumentRoot) 是:

DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"

修改 Apache 文件根目录 (DocumentRoot) 的操作如下:

1. 为避免修改失误,请先备份你的 Apache 配置文件 httpd.conf,该配置文件的路径是:

C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf

2. 打开 http.conf 文件,找到 DocumentRoot 为开头的那一行,将

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"

改成新的 DocumentRoot 路径,比如你新的路径为 C:\htdocs,就改成

DocumentRoot "C:/htdocs"

3. 然后找到 http.conf 文件中的如下内容

# This should be changed to whatever you set DocumentRoot to.#<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">

将 Diectory 中的路径改成你新设的文件根目录,比如:

<Directory "C:/htdocs">

4. 保存配置文件http.conf 。

5. 修改了配置文件以后,应重新启动 Apache Service。(Start --> All Programs --> Apache HTTP Server 2.2 --> Monitor Apache Servers --> Restart)

修改了文件根目录之后,你就可以将你的网页存放在新设的目录下了。




------------------------------------------------------------------------------------------------------------------------------------

设置Apache 虚拟目录(Virtual Directory)

上一章节我们讲了如何设置 Apache 的文件根目录 (DocumentRoot),这一章节我们讲述如何设置 Apache 虚拟目录。

假设你的 Apache 文件根目录是:

C:\htdocs

你要设置一个虚拟目录,别名(Alias) 为b,虚拟目录路径为C:\htdocs\blabla

你需要在 Apache 的配置文件 http.conf 里加上下面几句代码:

Alias /b/ "C:/htdocs/blabla/"<Directory "C:/htdocs/blabla">    Options Indexes FollowSymLinks    AllowOverride None    Order allow,deny    Allow from all</Directory>

然后保存配置文件http.conf 。

修改了配置文件以后,应重新启动 Apache Service。(Start --> All Programs --> Apache HTTP Server 2.2 --> Monitor Apache Servers --> Restart)

Apache Service 重启之后,该虚拟目录就生效了。

比如你写一个最简单的 test.php 文件(参见安装PHP 中的测试 PHP),然后将其存放在 C:\htdocs\blabla 目录下,然后在浏览器里打如下地址即可执行该php文件.

http://localhost:8080/b/test.php

该php 文件的实际路径是:

C:\htdocs\blabla\test.php
 

原文地址: 

http://www.blabla.cn/php/apache_change_documentroot.html

http://www.blabla.cn/php/apache_virtual_directory_config.html
0 0