nginx填坑之路(1)Nginx 检测语法正常,启用报 [emerg] bind() to 0.0.0.0:XXXX failed (13: Permission denied)错误处理
参考文档:
Nginx 启动报 [emerg] bind() to 0.0.0.0:XXXX failed (13: Permission denied)错误处理
nginx 启动失败: 检测语法正常,启用端口报错:[emerg] bind() to 0.0.0.0:XXXX failed (13: Permission denied)错误处理
nginx启动报错详细日志
[root@localhost conf.d]# systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Mon 2022-08-01 22:24:46 KST; 2min 50s ago Process: 27391 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 27600 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE) Process: 27598 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 27392 (code=exited, status=0/SUCCESS) Aug 01 22:24:46 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server... Aug 01 22:24:46 localhost.localdomain nginx[27600]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok Aug 01 22:24:46 localhost.localdomain nginx[27600]: nginx: [emerg] bind() to 0.0.0.0:8885 (13: Permission denied) 《===报错信息 Aug 01 22:24:46 localhost.localdomain nginx[27600]: nginx: configuration file /etc/nginx/nginx.conf test failed Aug 01 22:24:46 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1 Aug 01 22:24:46 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server. Aug 01 22:24:46 localhost.localdomain systemd[1]: Unit nginx.service entered failed state. Aug 01 22:24:46 localhost.localdomain systemd[1]: nginx.service failed. [root@localhost conf.d]# [root@localhost conf.d]# [root@localhost conf.d]# journalctl -xe Aug 01 22:24:46 localhost.localdomain nginx[27600]: nginx: [emerg] bind() to 0.0.0.0:8885 failed (13: Permission denied) 《===报错信息 Aug 01 22:24:46 localhost.localdomain nginx[27600]: nginx: configuration file /etc/nginx/nginx.conf test failed Aug 01 22:24:46 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1 Aug 01 22:24:46 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server. -- Subject: Unit nginx.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit nginx.service has failed. -- -- The result is failed. Aug 01 22:24:46 localhost.localdomain systemd[1]: Unit nginx.service entered failed state. Aug 01 22:24:46 localhost.localdomain systemd[1]: nginx.service failed. Aug 01 22:24:46 localhost.localdomain polkitd[620]: Unregistered Authentication Agent for unix-process:27592:10276196 (system bus name :1.223, object path /org/freedesktop/PolicyKit1/Authenti Aug 01 22:27:13 localhost.localdomain kernel: SELinux: 2048 avtab hash slots, 113338 rules. Aug 01 22:27:13 localhost.localdomain kernel: SELinux: 2048 avtab hash slots, 113338 rules. Aug 01 22:27:14 localhost.localdomain kernel: SELinux: 8 users, 14 roles, 5051 types, 318 bools, 1 sens, 1024 cats Aug 01 22:27:14 localhost.localdomain kernel: SELinux: 130 classes, 113338 rules Aug 01 22:27:14 localhost.localdomain kernel: SELinux: Converting 2343 SID table entries... Aug 01 22:27:16 localhost.localdomain dbus[617]: [system] Reloaded configuration Aug 01 22:27:20 localhost.localdomain kernel: SELinux: 2048 avtab hash slots, 113338 rules. Aug 01 22:27:20 localhost.localdomain kernel: SELinux: 2048 avtab hash slots, 113338 rules. Aug 01 22:27:20 localhost.localdomain kernel: SELinux: 8 users, 14 roles, 5051 types, 318 bools, 1 sens, 1024 cats Aug 01 22:27:20 localhost.localdomain kernel: SELinux: 130 classes, 113338 rules Aug 01 22:27:20 localhost.localdomain kernel: SELinux: Converting 2343 SID table entries... Aug 01 22:27:23 localhost.localdomain dbus[617]: [system] Reloaded configuration Aug 01 22:27:26 localhost.localdomain kernel: SELinux: 2048 avtab hash slots, 113338 rules. Aug 01 22:27:26 localhost.localdomain kernel: SELinux: 2048 avtab hash slots, 113338 rules. Aug 01 22:27:26 localhost.localdomain kernel: SELinux: 8 users, 14 roles, 5051 types, 318 bools, 1 sens, 1024 cats Aug 01 22:27:26 localhost.localdomain kernel: SELinux: 130 classes, 113338 rules Aug 01 22:27:26 localhost.localdomain kernel: SELinux: Converting 2343 SID table entries... Aug 01 22:27:29 localhost.localdomain dbus[617]: [system] Reloaded configuration
系统启动Nginx报错: [emerg] bind() to 0.0.0.0:XXXX failed (13: Permission denied)错误的处理方式,分为两种:
第一种:端口小于1024的情况:
[emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
原因是1024以下端口启动时需要root权限,所以sudo nginx
即可。 或者 修改/etc/nginx/nginx.conf
配置文件将user nginx;
改成 user root;
第二种:端口大于1024的情况:
[emerg] bind() to 0.0.0.0:8885 failed (13: Permission denied)
这种情况,需要如下操作:
1、查看http允许访问的端口:
semanage port -l | grep http_port_t
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t tcp 5988
2、将要启动的端口(8881)加入到如上端口列表中
semanage port -a -t http_port_t -p tcp 8885
标签:
nginx填坑之路
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)