zoukankan      html  css  js  c++  java
  • 解决SELinux阻止Nginx访问服务

    在使用 yum 安装 nginx 后可能会出现配置完成后却无法访问的问题,查看 audit.log 会发现类似于以下的错误信息

    audit.log

    出现此问题的原因是 SELinux 基于最小权限原则默认拦截了 Nginx 的请求,SELinux 是 Linux 的安全子系统,提供更安全的访问控制,许多运维人员嫌麻烦可能会直接关闭此组件,但是治标不治本,本文演示在启用 SELinux 基础上完成对 Nginx 请求的放行。

    1. 首先我们需要确认 SELinux 的运行状态,当然出现此问题肯定是运行中。
    [root@centos-server-02 local]# sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             targeted
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Max kernel policy version:      31
    

    临时关闭 SELinux:setenforce 0
    临时启动 SELinux:setenforce 1
    永久关闭/启动:修改/etc/sysconfig/selinux后重启系统

    1. 开启 HTTP 访问。
    [root@centos-server-01 audit]# setsebool -P httpd_can_network_connect 1
    
    1. 分析现有日志并生成关联模块,执行完此命令可以看到在当前目录下会生成后缀为*.pp*.te文件,如果该服务器上的服务未被访问过,此命令执行无效。
    [root@centos-server-01 audit]# ausearch -c 'nginx' --raw | audit2allow -M my-nginx
    
    1. 加载前一步生成的模块内容
    [root@centos-server-01 audit]# semodule -i my-nginx.pp
    
    1. 执行完成以上命令后即可对 Nginx 进行正常访问。
  • 相关阅读:
    【洛谷p1309】瑞士轮
    【洛谷p1190】接水问题
    KMP算法小记
    【洛谷p1051】谁拿了最多奖学金
    【洛谷p1781】宇宙总统
    【6.12校内test】T2 子集
    【6.12校内test】T3 城市交通费
    【6.12校内test】T1单词序列
    【洛谷p1464】 Function
    IOS基础之 (十二) 类的扩展
  • 原文地址:https://www.cnblogs.com/aotian/p/13222134.html
Copyright © 2011-2022 走看看