Apache中什么是DocumentRoot?
封面图
•
2025-10-21
•
APACHE
75
0
0
0
在 **Apache HTTP 服务器** 中,`DocumentRoot` 是一个非常重要的配置指令,它指定了 **Web 服务器的根目录**(即网站的默认访问路径)。 ### ✅ `DocumentRoot` 的作用: - 它告诉 Apache,当用户访问网站时(比如通过 `http://example.com/`),应该从哪个文件系统路径中查找网页文件。 - 例如:如果 `DocumentRoot` 设置为 `/var/www/html`,那么用户访问 `http://example.com/index.html` 时,Apache 会去读取 `/var/www/html/index.html` 文件。 --- ### 📁 示例配置: 在 Apache 的配置文件中(如 `httpd.conf` 或 `000-default.conf`),你可以看到类似这样的设置: ```apache DocumentRoot "/var/www/html" ``` 对应的 `<Directory>` 指令通常也会指向相同的路径: ```apache <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> ``` --- ### 🧠 说明: - `DocumentRoot` 是 **虚拟主机** 配置中的关键部分。 - 如果你有多个网站(虚拟主机),每个虚拟主机可以有自己的 `DocumentRoot`。 - 它不支持变量或动态路径,必须是绝对路径。 --- ### 🛠️ 如何查看当前的 DocumentRoot? 1. 找到 Apache 的主配置文件(通常是 `/etc/apache2/apache2.conf` 或 `/etc/httpd/conf/httpd.conf`)。 2. 查找 `DocumentRoot` 指令。 3. 或者使用命令行: ```bash apachectl -t -D DUMP_VHOSTS ``` 或者: ```bash grep -i 'documentroot' /etc/apache2/apache2.conf ``` --- ### 📘 总结: | 项目 | 说明 | |------|------| | 名称 | `DocumentRoot` | | 类型 | 配置指令 | | 作用 | 指定 Web 站点的根目录 | | 示例 | `DocumentRoot "/var/www/html"` | | 常见位置 | `httpd.conf`, `000-default.conf`, 虚拟主机配置文件 | 如果你有具体的 Apache 配置问题,也可以贴出来,我可以帮你分析。
上一篇:
如何在Apache中部署war或JAVA应用程序?
下一篇:
Apache中可用的日志级别是什么?
标题录入,一次不能超过6条
返回顶部
留言
留言
评论