Nginx 因 Selinux 服务导致无法远程访问
时间:2016-11-21 19:42 来源:http://blog.csdn.net/ 作者:王吉军
2014-12-16日
昨天晚上处理好的网络访问连接,早晨又访问不到了!
现象是Nginx可以获得 Respone Head信息,但Respone Body信息间歇性可以获取,Nginx配置为监听80端口,iptables 和 selinux 服务停止状态!
最终的处理结论是某IDC要求80端口必须申请白名单才可以访问,因为可以间歇性获取 Respone Body 导致对问题的误判,谨记!
2014-12-15日
本文暂且叫这个名吧,因为不是很理解 Selinux ,也许你有更好的办法请告知我!
一、问题现象
Nginx 启动后本机可以正常访问,使用Curl 命令可以获取默认 index.html,其他界面均不可访问。远程访问服务器时提示 400 bad request 信息,检查Nginx用户权限和端口都正常,iptables 未启动。
-
# 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
查询 selinux 运行模式
-
$ getenforce
-
Enforcing
运行模式分为三种 enforcing (强制模式)、permissive(宽容模式)、disabled(关闭)
三、问题处理
既然分析问题可能出在 selinux ,那就尝试修复,修复方式分为两种临时修复和永久修复!
临时修复,网上盛传方式。
-
# setenforce 0 #关闭 Selinux
-
# setenforce 1 #开启 Selinux
实际上可以运行下试试效果,本人运行结果是在 enforcing 模式与 permissive 模式之间来回切换而已无任何效果,如果本人理解错误,请指教!
永久方式,确实可用,需要重启服务器!
1、修改 /etc/selinux/config 文件
-
# vim /etc/selinux/config
2、修改 SELINUX=disabled ,修改后内容
-
# 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
3、重启电脑查看 Selinux 状态,应该为关闭状态
-
$ getenforce
-
Disabled
四、问题总结
1、未停止 Selinux 服务时,文件新增、修改目录都是带着点的,参见 default.html 和 index.html。
2、停止 Selinux 服务后,文件新增将不受 Selinux 服务保护,也就是不带点了,参见 welcome.html。
第一次处理 Selinux 问题,若实际问题与解决方案有出入请告知我,虚心学习!谢谢! (责任编辑:IT)
2014-12-16日 昨天晚上处理好的网络访问连接,早晨又访问不到了! 现象是Nginx可以获得 Respone Head信息,但Respone Body信息间歇性可以获取,Nginx配置为监听80端口,iptables 和 selinux 服务停止状态! 最终的处理结论是某IDC要求80端口必须申请白名单才可以访问,因为可以间歇性获取 Respone Body 导致对问题的误判,谨记!
2014-12-15日 本文暂且叫这个名吧,因为不是很理解 Selinux ,也许你有更好的办法请告知我! 一、问题现象Nginx 启动后本机可以正常访问,使用Curl 命令可以获取默认 index.html,其他界面均不可访问。远程访问服务器时提示 400 bad request 信息,检查Nginx用户权限和端口都正常,iptables 未启动。
注意观察 html 目录下 50x.html 、default.html、index.html 这三个文件权限后的点以及 welcome.html 文件权限的差别。 二、问题分析 谷歌、度娘一番,最终结论为 selinux 保护目录都会在文件以及文件夹后有个点 查询 selinux 状态
三、问题处理 既然分析问题可能出在 selinux ,那就尝试修复,修复方式分为两种临时修复和永久修复! 临时修复,网上盛传方式。
永久方式,确实可用,需要重启服务器! 1、修改 /etc/selinux/config 文件
四、问题总结 1、未停止 Selinux 服务时,文件新增、修改目录都是带着点的,参见 default.html 和 index.html。 2、停止 Selinux 服务后,文件新增将不受 Selinux 服务保护,也就是不带点了,参见 welcome.html。第一次处理 Selinux 问题,若实际问题与解决方案有出入请告知我,虚心学习!谢谢! (责任编辑:IT) |