linux 搭建apache服务器出现You don‘t have permission to access / on this server.

前提

这里我将/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权限
再重新访问 发现可以正常访问
在这里插入图片描述

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值