一、问题现象
Nginx 启动后本机可以正常访问,使用Curl 命令可以获取默认 index.html,其他界面均不可访问。远程访问服务器时提示 400 bad request 信息,检查Nginx用户权限和端口都正常,iptables 未启动。
检查目录时发现目录权限后缀都有个点。
查询 selinux 运行模式
运行模式分为三种 enforcing (强制模式)、permissive(宽容模式)、disabled(关闭)
先运行下试试效果,本人运行结果是在 enforcing 模式与 permissive 模式之间来回切换 ,如果可以正常运行,那这个坑就是selinux挖的。。。。。。然后继续下一步,一劳永逸!!!!
2、修改 SELINUX=disabled ,修改后内容
3、重启电脑查看 Selinux 状态,应该为关闭状态
第一次处理 Selinux 问题,若实际问题与解决方案有出入请告知我,虚心学习!谢谢!
Nginx 启动后本机可以正常访问,使用Curl 命令可以获取默认 index.html,其他界面均不可访问。远程访问服务器时提示 400
- #
curl -I 123.123.123.123 - HTTP/1.1
200 OK - Server:
nginx - Date:
Mon, 15 Dec 2014 10:52:34 GMT - Content-Type:
text/html - Content-Length:
12 - Last-Modified:
Mon, 15 Dec 2014 10:00:36 GMT - Connection:
keep-alive - Accept-Ranges:
bytes
注意观察 html 目录下 50x.html 、default.html、index.html 这三个文件权限后的点以及 welcome.html 文件权限的差别。
二、问题分析
谷歌、度娘一番,最终结论为 selinux 保护目录都会在文件以及文件夹后有个点
查询 selinux 状态
- $
sestatus - SELinux
status: enabled - SELinuxfs
mount: /selinux - Current
mode: enforcing - Mode
from config file: enforcing - Policy
version: 24 - Policy
from config file: targeted
- $
getenforce - Enforcing
三、问题处理
既然分析问题可能出在 selinux ,那就尝试修复,修复方式分为两种临时修复和永久修复!
临时修复,网上盛传方式。
- #
setenforce 0 #关闭 Selinux - #
setenforce 1 #开启 Selinux
下面是永久方式,确实可用,需要重启服务器!
1、修改
- #
vim /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 - SELinux is fully disabled. - SELINUX=permissive
- #
SELINUXTYPE= type of policy in use. Possible values are: - #
targeted - Only targeted network daemons are protected. - #
strict - Full SELinux protection. - SELINUXTYPE=targeted
- $
getenforce - Permissive
四、问题总结
1、未停止 Selinux 服务时,文件新增、修改目录都是带着点的,参见 default.html 和 index.html。
2、停止 Selinux 服务后,文件新增将不受 Selinux 服务保护,也就是不带点了,参见 welcome.html。第一次处理 Selinux 问题,若实际问题与解决方案有出入请告知我,虚心学习!谢谢!