首页
首页
文章目录
  1. 故事背景:
  2. 解决方法:
    1. 方案一关闭selinux
    2. 方案二,通过semanage更新

nginx 启动报 [emerg] bind() to 0.0.0.0:XXXX failed (13: Permission denied)错误问题解决方法

故事背景:

今天给nginx做一个反向代理,直接复制粘贴

1
2
nginx -t
nginx -s reload

一顿操作,然后发现。。。端口启动失败!!!

检查配置文件

1
2
3
4
5
6
7
8
9
10
server {
listen 7777;
location / {
proxy_redirect off;
proxy_pass https://oapi.dingtalk.com
}
location = /favicon.ico {
log_not_found off;
}
}

没问题啊

1
systemctl restart nginx

启动失败

1
journalctl -xe

回显信息

1
2
3
4
-- Unit nginx.service has begun starting up.
1006 15:12:45 account-mac nginx[26124]: nginx: [emerg] bind() to 0.0.0.0:7777 failed (13: Permission denied)
1006 15:12:45 account-mac systemd[1]: nginx.service: control process exited, code=exited status=1
1006 15:12:45 account-mac systemd[1]: Failed to start nginx - high performance web server.

解决方法:

方案一关闭selinux

临时生效

1
setenforce 0

永久生效,需要重启

1
修改 /etc/selinux/config 文件中的 SELINUX="" 为 disabled

方案二,通过semanage更新

由于CentOS系统自带的chcon工具只能修改文件、目录等的文件类型和策略,无法对端口、消息接口和网络接口等进行管理

所以需要安装semanage来修改SELinux的相关配置工作。

安装semanage的方法,一顿yum,发现安装失败,请看下图

1
yum install semanage

nginx_error_01

安装semanage的解决方法

1
2
yum provides semanage
yum -y install policycoreutils-python.x86_64

nginx_error_02

查看selinux默认允许的配置

1
semanage port -l | grep http_port_t

nginx_error_03
注意:7777是我添加的端口默认不存在该端口

新增允许通过的端口

1
semanage port -a -t http_port_t  -p tcp 7777

以上

End!

支持一下
扫一扫,我会更有动力更新
  • 微信扫一扫
  • 支付宝扫一扫