Jak*_*son 12 centos apache-2.2
我使用 Webmin 创建了以下虚拟主机:
<VirtualHost *:80>
DocumentRoot "/var/www/whatever"
ServerName whatever.ourdomain
<Directory "/var/www/whatever">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
当重新启动 Apache 时,我得到
Starting httpd: Warning: DocumentRoot [/var/www/whatever] does not exist
Run Code Online (Sandbox Code Playgroud)
问题是,该目录绝对存在。我正盯着它看。pwd向我显示这是我当前的目录等。拼写正确并不难。我在 httpd 日志中找不到任何其他错误或警告。apache:apache 拥有目录和所有子目录/文件。这里没有任何符号链接或任何涉及的东西。我错过了什么,或者我还应该看什么来确定这是为什么?
操作系统是 CentOS 6.0
kbu*_*ien 16
这是 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
Run Code Online (Sandbox Code Playgroud)
如果是这样,一些比较检查可能会有所帮助。例如,服务器在 处有一个默认的 DocumentRoot /var/www/html,但我们希望它在/path/to/document/root.
如果 SELinux 没有主动处理资源,ls -dZ目录上将显示如下内容:
$ ls -dZ /path/to/document/root
? /path/to/document/root/
Run Code Online (Sandbox Code Playgroud)
另一方面,如果应用 SELinux 上下文,则ls -dZ看起来更像:
$ ls -dZ /path/to/document/root
drwxrws--x+ cfgadm cfgadmin system_u:object_r:file_t:s0 /path/to/document/root
Run Code Online (Sandbox Code Playgroud)
如果我们与一个工作的 DocumentRoot 进行比较,它看起来像:
$ ls -dZ /var/www/html
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
Run Code Online (Sandbox Code Playgroud)
在_r和_t涉及到-r(--role和-t(--type)参数chcon这里是一个切下的手册页:
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
Run Code Online (Sandbox Code Playgroud)
乍一看,以下内容似乎有效,但可能无效。
$ sudo chcon -R -t httpd_sys_content_t /path/to/document/root
Run Code Online (Sandbox Code Playgroud)
如果 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
Run Code Online (Sandbox Code Playgroud)
此时,Web 服务器可以看到该目录。
是的,我今晚学得很辛苦。
注意:根据RedHat 文档(5.6.1. Temporary Changes: chcon),在概念上使用chcon有一个缺点:
The chcon command changes the SELinux context for files. However, changes
made with the chcon command do not survive a file system relabel, or the
execution of the restorecon command.
Run Code Online (Sandbox Code Playgroud)
使用semanage和restorecon进行更永久的更改。一个简单的例子:
$ sudo semanage fcontext --add -t httpd_sys_content_t -s system_u \
"/path/to/document/root(/.*)?"
$ sudo restorecon -FR /path/to/document/root
Run Code Online (Sandbox Code Playgroud)
关于restorecon,请注意-F需要影响整个上下文(即用户和类型)。此外,-R表示递归地进行更改。参数-v或-p可以以详细或简洁的方式显示进度。使用-FRnv来查看在不实际进行任何更改的情况下会发生什么。
一旦以这种方式使用semanage,就可以使用如下命令查看本地安全更改:
$ sudo semanage export
Run Code Online (Sandbox Code Playgroud)
的输出semanage的出口可以保存和使用semanage的进口,使之更容易申请一组更改到各种系统中。
注意:此答案为站点提供了最基本的类型上下文。安全性可以更加精细。例如,使用如下命令查看可应用于 Web 服务器页面的类型列表:
$ seinfo -t | grep http
Run Code Online (Sandbox Code Playgroud)
注意:默认情况下可能不会安装semanage和seinfo等实用程序。至少在某些发行版上,所需的包可能会被命名为:
policycoreutils-python
setools-console
Run Code Online (Sandbox Code Playgroud)
我首先想到的是 Apache 是否有权访问该目录?
另外,这个:https : //stackoverflow.com/questions/3948038/apache-says-my-documentroot-directory-doesnt-exist
这听起来像 SELinux。我建议你使用它。查看 /var/log/audit 目录进行确认。
更糟糕的情况是,您可以随时关闭 selinux,如前所述,但我建议您改用它。例如,如果我要创建一个用于 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
Run Code Online (Sandbox Code Playgroud)
因此,如果发生这种情况,我只需应用另一个目录中的上下文,在本例中为 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69942 次 |
| 最近记录: |