即使设置 httpd_sys_content_t 后,Httpd 也无法访问文件

dul*_*shi 6 fedora selinux centos

我目前正在学习 SELinux。我正在按照RedHat 的 SELinux 文档中的说明进行操作。键入以下命令后,我确实成功了:

mkdir /mywebsite  
//add something to /mywebsite/index.html  
semanage fcontext -a -t httpd_sys_content_t "/mywebsite(/.*)?"  
restorecon -R -v /mywebsite //everythins worked well by then
Run Code Online (Sandbox Code Playgroud)

但后来我做了更多的事情:

chcon -R -t httpd_sys_content_t /mywebsite  //I can't access index.html now, as expected

restorecon -R -v /mywebsite //Still can't access index.html!!  

semanage fcontext -a -t httpd_sys_content_t "/mywebsite(/.*)?"  
restorecon -R -v /mywebsite  //didn't work, either

ls -dZ /mywebsite // unconfined_u:object_r:httpd_sys_content_t:s0
Run Code Online (Sandbox Code Playgroud)

Firefox 中的错误消息是:

Forbidden

You don't have permission to access /index.html on this server. 
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?或者这是一个错误?我的操作系统是带有 Apache 2.4.7 的 Fedora 20。

dul*_*shi 3

我的错。这不是 SELinux 的错。红帽教程并不完整。我们还应该将以下内容添加到 httpd 配置文件(对于 apache httpd 2.4):

<Directory "/mywebsite">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
Run Code Online (Sandbox Code Playgroud)