本文暂且叫这个名吧,因为不是很理解 Selinux ,也许你有更好的办法请告知我!
一、问题现象
Nginx 启动后本机可以正常访问,使用Curl 命令可以获取默认 index. html ,其他界面均不可访问。远程访问服务器时提示 400 bad request 信息,检查Nginx用户权限和端口都正常,iptables 未启动。
检查目录时发现目录权限后缀都有个点。
查询 selinux 运行模式
运行模式分为三种 enforcing (强制模式)、permissive(宽容模式)、disabled(关闭)
实际上可以运行下试试效果,本人运行结果是在 enforcing 模式与 permissive 模式之间来回切换而已无任何效果,如果本人理解错误,请指教!
2、修改 SELINUX=disabled ,修改后内容
3、重启电脑查看 Selinux 状态,应该为关闭状态
一、问题现象
Nginx 启动后本机可以正常访问,使用Curl 命令可以获取默认 index. html ,其他界面均不可访问。远程访问服务器时提示 400 bad request 信息,检查Nginx用户权限和端口都正常,iptables 未启动。
1
2
3
4
5
6
7
8
9
|
# curl -I localhost
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 状态
1
2
3
4
5
6
7
|
$ sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version:
24
Policy from config file: targeted
|
1
2
|
$ getenforce
Enforcing
|
三、问题处理
既然分析问题可能出在 selinux ,那就尝试修复,修复方式分为两种临时修复和永久修复!
临时修复,网上盛传方式。
1
2
|
# setenforce
0
#关闭 Selinux
# setenforce
1
#开启 Selinux
|
永久方式,确实可用,需要重启服务器!
1、修改 /etc/selinux/config 文件
1
|
# vim /etc/selinux/config
|
1
2
3
4
5
6
7
8
9
10
|
# 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=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are
protected
.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
|
1
2
|
$ getenforce
Disabled
|
四、问题总结
1、未停止 Selinux 服务时,文件新增、修改目录都是带着点的,参见 default.html 和 index.html。
2、停止 Selinux 服务后,文件新增将不受 Selinux 服务保护,也就是不带点了,参见 welcome.html。
转自http://www.2cto.com/os/201412/361686.html