Apache说DocumentRoot不存在的时候

我用Webmin来创build下面的虚拟主机:

<VirtualHost *:80> DocumentRoot "/var/www/whatever" ServerName whatever.ourdomain <Directory "/var/www/whatever"> allow from all Options +Indexes </Directory> </VirtualHost> 

当我重新启动Apache时,

 Starting httpd: Warning: DocumentRoot [/var/www/whatever] does not exist 

事情是,目录绝对存在。 我正盯着它。 pwd显示我这是我目前的目录等等。拼写正确并不难。 我在httpd日志中找不到任何其他错误或警告。 apache:apache拥有目录和所有的子目录/文件。 这里没有任何符号链接或任何涉及的东西。 我错过了什么,还有什么我应该看看,以确定这是为什么?

OS是CentOS 6.0

我想到的第一件事是,Apache是​​否有权限访问该目录?

另外,这: https : //stackoverflow.com/questions/3948038/apache-says-my-documentroot-directory-doesnt-exist

以下是SELinux案例的教程方法:

了解SELinux是否有效:

  $ sestatus SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 24 Policy from config file: targeted 

如果是这样,一些比较检查可能有帮助。 例如,服务器在/var/www/html有一个默认的DocumentRoot,但是我们希望它在/path/to/document/root

如果SELinux没有主动搞乱这个资源,目录下的ls -dZ会显示如下内容:

 $ ls -dZ /path/to/document/root ? /path/to/document/root/ 

另一方面,如果应用SELinux上下文, ls -dZ看起来更像:

 $ ls -dZ /path/to/document/root drwxrws--x+ cfgadm cfgadmin system_u:object_r:file_t:s0 /path/to/documentroot 

如果我们比较一下正在运行的DocumentRoot,它看起来像这样:

 $ ls -dZ /var/www/html drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html 

_r_t--role -r (– --role-t (– --type )参数相关,下面是一个精简的手册页:

 NAME chcon - change file security context SYNOPSIS chcon [OPTION]... CONTEXT FILE... chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... chcon [OPTION]... --reference=RFILE FILE... DESCRIPTION Change the security context of each FILE to CONTEXT. With --reference, change the security context of each FILE to that of RFILE. --reference=RFILE use RFILE's security context rather than specifying a CONTEXT value -R, --recursive operate on files and directories recursively 

初步猜测,以下几点似乎可行,但可能不行。

 $ sudo chcon -R -t httpd_sys_content_t /path/to/document/root 

如果Web服务器仍然无法看到DocumentRoot,请注意,上下文一直回到根目录:

 $ sudo chcon -R -t httpd_sys_content_t /path/to/document $ sudo chcon -R -t httpd_sys_content_t /path/to $ sudo chcon -R -t httpd_sys_content_t /path 

此时,Web服务器可以看到该目录。

是的,今天晚上我学会了艰辛的道路。

听起来像SELinux.I会build议你使用它。 查看/ var / log / audit目录确认。

更糟糕的是,如前所述,您可以closuresselinux,但我build议您使用它。 例如,如果我要创build一个供Apache使用的目录,则不会有正确的上下文,如此处所述。

 [root@amp23140 www]# ls -Z drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 error drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 icons drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 whatever 

所以如果发生这种情况,我只是应用来自另一个目录,在这种情况下,是HTML的上下文:

 [root@amp23140 www]# chcon whatever --reference=html [root@amp23140 www]# ls -lZ drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 error drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 icons drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 whatever 

在root中使用这个命令来改变允许Apache执行的“httpd_sys_content_t”的安全上下文。

 chcon -R -h -t httpd_sys_content_t /var/www/whatever 

使用ls -dZ /var/www/whatever来查看详细的安全angular色