【发布时间】:2014-08-10 16:49:20
【问题描述】:
我正在尝试配置 Apache httpd.conf(在我的 CentOS 6.4 上)以允许访问我的用户目录(即 ~me/public_html/index.html)。
我将原来的httpd.conf(即开箱即用)更改如下:
[root@myhost www]# diff /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.orig.out-of-the-box
366c366
< #UserDir disabled
---
> UserDir disabled
373c373
< UserDir public_html
---
> #UserDir public_html
这原则上应该提供对http://myhost/~me 的访问权限,但相反,我得到了可怕的错误:
You don't have permission to access /~me on this server.
我检查了 /var/log/httpd/error_log 文件,果然,上面写着:
(13)Permission denied: access to /~me denied
我注意到的第一件奇怪的事情是/ 被添加到~me 前面。
- 领先的
/来自哪里? - 这只是“红鲱鱼”吗?
- 或者这是否指向问题的根本原因(即我需要在 httpd.conf 中修改的其他内容)?
最重要的是,由于我知道我的~me/public_html 具有全球可读权限,我该如何解决此类问题?
有没有办法找出为什么“访问 /~me 被拒绝”?
- SELinux?
- httpd.conf?
- 目录权限?
- 以上所有?
更新 1,回答下面@UlrichSchwarz 在 cmets 中的 2 个问题:
-
主目录似乎确实有 'x' 权限:
[root@myhost ~]# ls -lad /home/me
drwxr-xr-x。 33 me me 4096 Feb 8 16:30 /home/me
-
public_html 上的 SELinux 信息:
[root@myhost ~]# ls -Z -d /home/me/public_html/
drwxrwxr-x。我我 unconfined_u:object_r:file_t:s0 /home/me/public_html/
更新 2,在我确认这确实是一个 SELinux 问题之后(感谢 @Scolytus 的提示):
-
我运行了命令:
chcon -R -t httpd_user_content_t /home/me/public_html/
还是不行。
[root@myhost ~]# ls -Z -d /home/me/public_html/
drwxrwxr-x。我我 unconfined_u:object_r:httpd_user_content_t:s0 /home/me/public_html/
-
然后我运行“允许 HTTPD 读取主目录”from the command line:
setsebool -P httpd_enable_homedirs=1
还是不行。
/var/log/httpd/error_log 现在显示(除了 (13)permission denied 错误)以下内容:
[notice] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[notice] Digest: generating secret for digest authentication ...
[notice] Digest: done
[notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations
也许问题在于 context_system_u 和 httpd_user_content_t 之间的差异?
我还需要做什么? (即没有完全禁用 SELinux)
更新 3,感谢@lserni 回答中的信息,我发现了ausearch 命令:
ausearch -m avc --start today
它提供了以下输出:
time->Fri Jul 4 09:16:44 2014
type=SYSCALL msg=audit(1404479804.256:1312): arch=40000003 syscall=196 success=no exit=-13 a0=12c2c80 a1=bfeb1d00 a2=a34ff4 a3=2008171 items=0 ppid=5880 pid=5886 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=193 comm="httpd" exe="/usr/sbin/httpd" subj=unconfined_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1404479804.256:1312): avc: denied { getattr } for pid=5886 comm="httpd" path="/home/me" dev=dm-3 ino=2 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:file_t:s0 tclass=dir
嗯?为什么是/home/me 而不是/home/me/public_html?
这是ls -Zd /home/me/的输出:
drwxr-xr-x. me me system_u:object_r:file_t:s0 /home/me/
我也应该在 /home/me 上运行 chcon -t httpd_user_content_t 吗?
继续研究...
更新 4:成功!
我运行了命令:
chcon -t httpd_user_content_t /home/me/
现在一切都很好。
[root@myhost sa]# ls -Z -d /home/me/
drwxr-xr-x. me me system_u:object_r:httpd_user_content_t:s0 /home/me/
【问题讨论】:
-
服务器可能首先需要在您的主目录上使用
+x,以查看您是否首先存在public_html,是这样吗? -
你能发布
ls -Z -d public_html/的输出吗? (-Z列出 SELinux 信息;这取自 the SELinux FAQ) -
您可以尝试暂时禁用 SELinux,看看是否真的是问题所在。
-
您可能想要检查/安装
sealert/setroubleshootd组合。它可以成为救生员。在我的 OpenSuSE 系统上,我可以在 /var/log "auditd" 日志文件中找到一些 SE 问题;你用的是什么发行版? -
当然。傻我:为了能够访问
/home/me/public_html,Apache 需要有权读取/home/me 目录内容(即那里的文件和目录的名称 - 目录执行位)。见askubuntu.com/questions/26848/…
标签: apache httpd.conf