前提
这里我将/etc/httpd/conf/httpd.conf 里面的DocumentRoot 设置为/home/skindow/wwwroot ,且将对应的Directory 的参数也设置为了"/home/skindow/wwwroot "
DocumentRoot "/home/skindow/wwwroot"
#
# Relax access to content within /var/www.
#
<Directory "/home/skindow/wwwroot">
AllowOverride None
#Allow open access:
Require all granted
</Directory>
一.首先排除SELinux服务安全机制的问题
简单描述下SELinux服务安全机制,对服务进程资源进行监控限制,对文件资源进行限制,主要限制服务非法读取文件资源,比如读取用户目录资源,我这次搭建的apache服务就是搭建在用户目录中的/skindow/home
首先我们查看SElinux配置模式
getenforce
SElinux主要有三种配置模式如下
- enforcing:强制启用安全策略模式,将拦截服务的不合法请求。
- permissive:遇到服务越权访问时,只发出警告而不强制拦截。
- disabled:对于越权的行为不警告也不拦截。
setenforce 0 #临时关闭SElinux
二.文件本身权限限制
如果第一步还没有解决问题,这个时候我们可以查看apche错误日志
cat /var/log/httpd/error_log
以下为日志信息
[Thu Dec 17 16:49:41.910535 2020] [core:error] [pid 26740] (13)Permission denied: [client 219.139.193.142:2082] AH00035: access to / denied (filesystem path '/home/skindow/wwwroot') because search permissions are missing on a component of the path
[Thu Dec 17 16:50:35.807373 2020] [core:error] [pid 26743] (13)Permission denied: [client 219.139.193.142:2085] AH00035: access to / denied (filesystem path '/home/skindow/wwwroot') because search permissions are missing on a component of the path
[Thu Dec 17 16:50:36.970992 2020] [core:error] [pid 26743] (13)Permission denied: [client 219.139.193.142:2085] AH00035: access to / denied (filesystem path '/home/skindow/wwwroot') because search permissions are missing on a component of the path
[Thu Dec 17 16:55:44.413548 2020] [core:error] [pid 26740] (13)Permission denied: [client 219.139.193.142:2089] AH00035: access to / denied (filesystem path '/home/skindow/wwwroot') because search permissions are missing on a component of the path
通过日志发现,apche服务进程无法访问/home/skindow/wwwroot目录里面的资源
此时我们对该目录加上rwx权限就行了
chmod -R o+rwx /home/skindow
注意:这里我一开始是对/home/skindow/wwwroot该目录添加rwx权限,发现还是无法访问,最后发现/home/skindow 在其他用户权限中为—,所以无法访问,这里注意上级目录也要有rwx权限
再重新访问 发现可以正常访问