CentOS7下Apache服务器提示无权访问

一、问题描述
最近在CentOS7上配置apache服务器,配置好后修改apache主配置文件 /etc/httpd/conf/httpd.conf
将DocumentRoot修改为自己指定的目录,如/httpd
然后重启httpd服务,访问相应地址,提示如下:

Forbidden

You don't have permission to access XXX on this server

二、解决方法
一般情况下出现403禁止访问的问题,说明权限不足。解决方案如下:

1.查看文件权限
因为是运行apache的用户,要保证apache用户有访问/httpd及其子目录的权限。

2.修改httpd.conf配置文件
检查/httpd的目录权限,“Options Indexes FollowSymLinks”是否存在。

vi /etc/httpd/conf/httpd.conf

DocumentRoot "/httpd"

……

<Directory "/httpd">
    Options Indexes FollowSymLinks
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

 一般通过修改这两点就可以解决问题,但是结果还是不行,通过查资料得知还需要关闭selinux

3.关闭SELinux
将/etc/selinux/config文件中的SELINUX=enforcing 修改为 disabled,然后重启生效。

vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

重启:reboot -f

三、SELinux 的作用及权限管理机制

SELinux 主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)。
SELinux 有三种工作模式,分别是:
1、enforcing:强制模式。违反 SELinux 规则的行为将被阻止并记录到日志中。

2、permissive:宽容模式。违反 SELinux 规则的行为只会记录到日志中。一般为调试用。

3、disabled:关闭 SELinux。

SELinux 工作模式可以在 /etc/selinux/config 中设定。

如果想从 disabled 切换到 enforcing 或者 permissive 的话,需要重启系统。反过来也一样。

enforcing 和 permissive 模式可以通过 setenforce 1|0 命令快速切换。

需要注意的是,如果系统已经在关闭 SELinux 的状态下运行了一段时间,在打开 SELinux 之后的第一次重启速度可能会比较慢。因为系统必须为磁盘中的文件创建安全上下文。

SELinux 日志的记录需要借助 auditd.service 这个服务,请不要禁用它。


参考资料:
https://www.linuxidc.com/Linux/2011-07/38665.htm
https://zhidao.baidu.com/question/372547424641398564.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值