yum安装的nginx以及解决selinux导…

一、问题现象


yum安装的nginx以及解决selinux导致无法访问的问题



Nginx 启动后本机可以正常访问,使用Curl 命令可以获取默认 index.html,其他界面均不可访问。远程访问服务器时提示 400 bad request 信息,检查Nginx用户权限和端口都正常,iptables 未启动。
[plain]  view plain  copy
  1. curl -I 123.123.123.123  
  2. HTTP/1.1 200 OK  
  3. Server: nginx  
  4. Date: Mon, 15 Dec 2014 10:52:34 GMT  
  5. Content-Type: text/html  
  6. Content-Length: 12  
  7. Last-Modified: Mon, 15 Dec 2014 10:00:36 GMT  
  8. Connection: keep-alive  
  9. Accept-Ranges: bytes  
检查目录时发现目录权限后缀都有个点。

 


注意观察 html 目录下 50x.html 、default.html、index.html 这三个文件权限后的点以及 welcome.html 文件权限的差别。

二、问题分析

谷歌、度娘一番,最终结论为 selinux 保护目录都会在文件以及文件夹后有个点

查询 selinux 状态

 

[plain]  view plain  copy
  1. sestatus  
  2. SELinux status:                 enabled  
  3. SELinuxfs mount:                /selinux  
  4. Current mode:                   enforcing  
  5. Mode from config file:          enforcing  
  6. Policy version:                 24  
  7. Policy from config file:        targeted  
查询 selinux 运行模式

 

[plain]  view plain  copy
  1. getenforce  
  2. Enforcing   
运行模式分为三种 enforcing (强制模式)、permissive(宽容模式)、disabled(关闭)

三、问题处理

既然分析问题可能出在 selinux ,那就尝试修复,修复方式分为两种临时修复和永久修复!

临时修复,网上盛传方式。

[plain]  view plain  copy
  1. setenforce #关闭 Selinux  
  2. setenforce #开启 Selinux  

yum安装的nginx以及解决selinux导致无法访问的问题



 先运行下试试效果,本人运行结果是在 enforcing 模式与 permissive 模式之间来回切换 ,如果可以正常运行,那这个坑就是selinux挖的。。。。。。然后继续下一步,一劳永逸!!!!

 

下面是永久方式,确实可用,需要重启服务器!

1、修改 /etc/selinux/config 文件

[plain]  view plain  copy
  1. vim /etc/selinux/config  
2、修改 SELINUX=disabled ,修改后内容

 

[plain]  view plain  copy
  1. This file controls the state of SELinux on the system.  
  2. SELINUX= can take one of these three values:  
  3.       enforcing SELinux security policy is enforced.  
  4.       permissive SELinux prints warnings instead of enforcing.  
  5.       disabled SELinux is fully disabled.  
  6. SELINUX=permissive 
  7. SELINUXTYPE= type of policy in use. Possible values are:  
  8.       targeted Only targeted network daemons are protected.  
  9.       strict Full SELinux protection.  
  10. SELINUXTYPE=targeted  
3、重启电脑查看 Selinux 状态,应该为关闭状态
[plain]  view plain  copy
  1. getenforce   
  2. Permissive 

四、问题总结

1、未停止 Selinux 服务时,文件新增、修改目录都是带着点的,参见 default.html 和 index.html。

2、停止 Selinux 服务后,文件新增将不受 Selinux 服务保护,也就是不带点了,参见 welcome.html。
第一次处理 Selinux 问题,若实际问题与解决方案有出入请告知我,虚心学习!谢谢!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值