Apache权限被拒绝

我正在尝试使用CentOS 6和Apache启动一个networking服务器。 这些网站的文件被托pipe在Windows文件共享中。 这里是从fstab文件到安装网页文件的行: \\192.168.1.10\apache /var/www/html cifs credentials=/root/secret.txt,uid=apache,gid=apache 0 0 。 这似乎工作正常。

这是vhost.conf文件:

 Listen 80 <VirtualHost *:80> ServerAdmin [email protected] ServerName sub.domain.com DocumentRoot "/var/www/html/domain.com/sub/public_html" #ErrorLog /var/www/html/domain.com/sub/logs/error.log #CustomLog /var/www/html/domain.com/sub/logs/access.log combined </VirtualHost> 

我运行命令ls -l /var/www/html/domain.com/sub/public_html ,这里是输出:

 total 1 -rwxr-xr-x. 0 apache apache 0 Jan 26 20:43 index2.txt -rwxr-xr-x. 0 apache apache 45 Jan 26 19:33 index.html 

命令ls -l /var/www/html/domain.com/sub输出是:

 total 0 drwxr-xr-x. 0 apache apache 0 Jan 26 20:00 logs drwxr-xr-x. 0 apache apache 0 Jan 26 20:43 public_html 

当我去http://sub.domain.com ,我得到了通用的Apache屏幕。 一时兴起,我去了http://sub.domain.com/index.htmlurl; 浏览器说我没有访问页面的权限 – 对于http://sub.domain.com/index2.txt也是这样 。 对于http://sub.domain.com/index2.html这个URL,浏览器说这个文件不存在 。 这告诉我,我的“手指”都指向正确的方向。 任何想法可能是我的问题?

vhost.conf文件中的日志行被注释掉了,因为httpd不会重新启动。 我认为这是同样的问题。

由于Apache设置本身没有明显的问题,因此必须是OS设置的权限问题。

Apache要求apache用户也可以访问父目录。

由于CentOS自带SELinux,这也可能是问题所在。 也许你没有使用SELinux进行主动的权限设置,但是Linux本身具有远程挂载的默认SELinux设置。

你可以用ls -Z来检查。

这里有一个有趣的OP在askubuntu: https ://askubuntu.com/questions/451922/apache-access-denied-because-search-permissions-are-missing

我们可以看到你的问题,你正在运行SELinux,并试图让Apache从CIFS共享中读取网页内容。 默认情况下,SELinux不允许这样做,但是可以通过设置适当的布尔值来启用它。

 setsebool -P httpd_use_cifs 1 

问题出在SELinux上。 我安装共享的方式,SELinux安全上下文将不允许Apache访问共享中的文件。 在SELinux的例子如何Tos只是为了Apache。

我使用了命令ls -Z ,而不仅仅是ls -l ,而且我看到了安装文件的SELinux安全上下文是错误的。 我改变了fstab文件中的行

 \\192.168.1.100\apache /var/www/html cifs credentials=/root/apache.pass,uid=apache,gid=apache,context=‌​system_u:object_r:ht‌​tpd_sys_content_t:s0 0 0 

这个添加的上下文参数是SELinux允许Apache访问文件所需要的。