Apache (13) 权限被拒绝:访问/~me被拒绝
我正在尝试配置Apache httpd.conf(在CentOS 6.4上)以允许访问我的用户目录(即~me/public_html/index.html) 我更改了原始的httpd.conf(即开箱即用),如下所示:Apache (13) 权限被拒绝:访问/~me被拒绝,apache,httpd.conf,Apache,Httpd.conf,我正在尝试配置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 --- &g
[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
我检查了文件/var/log/httpd/error\u log,果然是这样的:
(13)Permission denied: access to /~me denied
我注意到的第一件奇怪的事情是/
在~me
前面加了一个前缀
- 前面的
来自哪里李>/
- 这只是一个“红鲱鱼”吗李>
- 或者这是指向问题的根本原因(即我需要在httpd.conf中修改的其他内容)
~me/public\u html
具有全球可读权限,如何解决此类问题?
有没有办法找出“拒绝访问我”的原因
- 塞利努克斯
- httpd.conf
- 目录权限
- 所有这些
更新1,回答以下@ulrichswarz评论中的两个问题:
更新2,在我确认这确实是一个SELinux问题后(感谢@Scolytus的提示):
chcon -t httpd_user_content_t /home/me/
chcon-R-t httpd\u user\u content\u t/home/me/public\u html/
还是不行
[root@myhost~]#ls-Z-d/home/me/public#html/
drwxrwxr-x。me未定义\u u u:object\r:httpd\u user\u content\u t:s0/home/me/public\u html/ [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
也许问题在于上下文系统和httpd用户内容之间的差异
我还需要做什么?(即,不完全禁用SELinux)
更新3,多亏@lserni回答中的信息,我发现了以下命令: 它提供了以下输出:
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\u html
下面是ls-Zd/home/me/的输出:
drwxr-xr-x. me me system_u:object_r:file_t:s0 /home/me/
我是否也应该在/home/me上运行chcon-t httpd\u user\u content\u 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/
我不能立即检查,但我记得注释掉禁用的
UserDir
与启用不一样
更具体地说,我认为您需要在https.conf文件中包含一行
Userdir enabled me
我已经看到了您发出的命令,由sealert
提供:
SELinux拒绝访问httpd请求的/var/www/html/file1。
/var/www/html/file1有一个上下文,用于不同用户共享
节目。如果您想从httpd共享/var/www/html/file1
另外,您需要将其文件上下文更改为public\u content\t
。如果
您不打算访问此访问,这可能表示有人入侵
尝试
允许访问:
您可以通过执行chcon-t public\u content\t来更改文件上下文
“/var/www/html/file1”
修复命令:
chcon -t public_content_t '/var/www/html/file1'
如何解决此类问题?
大多数与SELinux相关的信息通常都在已审核的日志中,但您可能需要一些工具,例如sealert
来为您解码。我做了一个简短的搜索,找到了这个我不知道但似乎很有趣的工具:
附录:服务器可能需要在您的主目录上显示
+x
,以查看您首先是否有public\u html
存在,是这样吗?您可以发布ls-Z-d public\u html/
的输出吗?(-Z
列出了SELinux信息;此信息取自)您可以尝试暂时禁用SELinux,以查看是否确实存在问题。您可能需要检查/安装sealert
/setroubleshootd
组合。它可以成为救命稻草。在我的OpenSuSE系统上,我可以在/var/log“auditd”日志文件中找到一些SE问题;你在用什么发行版?当然。愚蠢的我:为了能够访问/home/me/public_html
,Apache需要有权读取/home/me目录内容(即其中的文件和目录的名称-目录执行位)。使用添加的行UserDir public\u html
查看一切正常。我猜你不理解diff
的输出。此外,@Nick的回答是在我发布了关于这个问题的发现后得出的,这个问题只是一个SELinux问题。作为记录,当我发布我的报价时,SELinux的东西不在那里。考虑到你评论的孩子气的任性,我怀疑我在你出生之前使用了diff(大约从1981年开始)。如果您在第一个实例中对问题进行了详尽的描述(即承认使用了SELinux,而不仅仅是谈论权限),我就不会发布@lsemi+1来试图解决这个谜。我运行了您的chcon-t public\u content\t
命令,但也没有任何帮助。我怀疑这个问题与日志中关于“httpd作为上下文系统运行”的内容有关,只是为了确保,在默认的httpd DocumentRoot上运行一个ls-lZ
,Apache能够读取该文档。之后,您可以使用semanage
/restorecon
将相同的上下文分配给public\u html目录。另请参见:drwxr-xr-x。根系统:对象:httpd\u系统\u控制
chcon -t public_content_t '/var/www/html/file1'