当httpd.conf中DocumentRoot被注释时,httpd内容根目录在哪?如何查询?
Nice question! Let's break this down for your CentOS Linux release 7.4.1708 (Core) and Apache/2.4.6 (CentOS) setup:
1. What's the active DocumentRoot when the httpd.conf line is commented?
First, let's clear up the confusion around /usr/local/apache/htdocs: that's the default DocumentRoot for source-compiled Apache, but the CentOS yum package uses a standardized filesystem layout instead.
Here's what happens when you comment out the DocumentRoot directive in /etc/httpd/conf/httpd.conf:
- Apache will fall back to its compile-time default value. For your yum-installed Apache, this is almost certainly
/var/www/html. You can verify this directly with:
You should see output likehttpd -V | grep DOCUMENT_ROOT-D DOCUMENT_ROOT="/var/www/html"— that's the directory Apache will use. - Keep in mind Apache loads additional config files from
/etc/httpd/conf.d/(via theInclude conf.d/*.confline in httpd.conf). If any of those files define aDocumentRoot, that will take precedence over the compile-time default. But by default, none of the stock conf.d files override this setting.
2. Tools to check the active DocumentRoot
You were right to look at apachectl — it does work, you just need the right flag! Here are the most reliable methods:
Use apachectl/httpd -S (recommended)
This command outputs a summary of Apache's active configuration, including the DocumentRoot for the default server and any virtual hosts. It's the best option because it accounts for all loaded config files, not just a single one:
apachectl -S # Or the equivalent direct command: httpd -S
Look for lines like DocumentRoot "/var/www/html" in the output — that's your active content root directory.
Search all config files manually
If you want to track down every occurrence of the DocumentRoot directive across your Apache configs, use grep to scan the main config directory and included subdirectories:
grep -r "DocumentRoot" /etc/httpd/conf /etc/httpd/conf.d
This will show you exactly where the directive is defined (if anywhere) across all loaded files.
内容的提问来源于stack exchange,提问作者Randall Stevens

