Nginx 错误处理方法: bind() to 0.0.0.0:80 failed

本文介绍了解决Nginx在Windows上启动时遇到80端口被占用的问题,通过查找并终止占用80端口的进程,如Apache的httpd,最终成功启动Nginx。

启动window上的nginx总是报错

转自:http://blog.youkuaiyun.com/zero_295813128/article/details/50914233

错误信息是bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

大概意思是 nginx listen的80后端口被占用   于是百度了下查看端口的命令

运行–cmd

C:\>netstat -aon|findstr "80" 
TCP 127.0.0.1:80 0.0.0.0:0 LISTENING 2448

端口被进程号为2448的进程占用,继续执行下面命令:
C:\>tasklist|findstr "2448" 

thread.exe 2016 Console 0 16,064 K
很清楚,thread占用了你的端口,Kill it
如果第二步查不到,那就开任务管理器,进程—查看—选择列—pid(进程位标识符)打个勾就可以了
看哪个进程是2448,然后杀之即可。

另外,强制终止进程: CMD命令:taskkill /F /pid 1408

其实上面我都还没解决问题 最后发现有个http.d 这个是apache的进程 结束了这个进程nginx才启动了

转载于:https://www.cnblogs.com/lojun/p/8479272.html

[root@localhost ~]# systemctl status nginx.service ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since 四 2025-09-18 09:19:57 CST; 53s ago Docs: http://nginx.org/en/docs/ Process: 14473 ExecStop=/bin/sh -c /bin/kill -s TERM $(/bin/cat /var/run/nginx.pid) (code=exited, status=1/FAILURE) Process: 13795 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE) Main PID: 18097 (code=exited, status=0/SUCCESS) 9月 18 09:19:55 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:9999 fail...e) 9月 18 09:19:56 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:80 failed...e) 9月 18 09:19:56 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:9999 fail...e) 9月 18 09:19:56 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:80 failed...e) 9月 18 09:19:56 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:9999 fail...e) 9月 18 09:19:57 localhost.localdomain nginx[13795]: nginx: [emerg] still could not bind() 9月 18 09:19:57 localhost.localdomain systemd[1]: nginx.service: control process exited, code=...=1 9月 18 09:19:57 localhost.localdomain systemd[1]: Failed to start nginx - high performance web...r. 9月 18 09:19:57 localhost.localdomain systemd[1]: Unit nginx.service entered failed state. 9月 18 09:19:57 localhost.localdomain systemd[1]: nginx.service failed. Hint: Some lines were ellipsized, use -l to show in full. [root@localhost ~]# journalctl -xe -- Unit session-2720.scope has finished starting up. -- -- The start-up result is done. 9月 18 09:19:13 localhost.localdomain sshd[13657]: pam_unix(sshd:session): session opened for user r 9月 18 09:19:54 localhost.localdomain polkitd[1191]: Registered Authentication Agent for unix-proces 9月 18 09:19:54 localhost.localdomain systemd[1]: Starting nginx - high performance web server... -- Subject: Unit nginx.service has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit nginx.service has begun starting up. 9月 18 09:19:54 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: 9月 18 09:19:54 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:9999 failed (98 9月 18 09:19:55 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: 9月 18 09:19:55 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:9999 failed (98 9月 18 09:19:55 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: 9月 18 09:19:55 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:9999 failed (98 9月 18 09:19:56 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: 9月 18 09:19:56 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:9999 failed (98 9月 18 09:19:56 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: 9月 18 09:19:56 localhost.localdomain nginx[13795]: nginx: [emerg] bind() to 0.0.0.0:9999 failed (98 9月 18 09:19:57 localhost.localdomain nginx[13795]: nginx: [emerg] still could not bind() 9月 18 09:19:57 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited 9月 18 09:19:57 localhost.localdomain systemd[1]: Failed to start nginx - high performance web serve -- 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. 9月 18 09:19:57 localhost.localdomain polkitd[1191]: Unregistered Authentication Agent for unix-proc 9月 18 09:19:57 localhost.localdomain systemd[1]: Unit nginx.service entered failed state. 9月 18 09:19:57 localhost.localdomain systemd[1]: nginx.service failed.
最新发布
09-19
在 CentOS 系统启动 Nginx 服务时,出现 `bind()` 到 `0.0.0.0:80` 和 `0.0.0.0:9999` 失败,导致 `nginx.service` 启动失败,可尝试以下解决办法: ### 检查端口占用情况 使用 `netstat` 或 `ss` 命令查看端口占用情况。 使用 `netstat` 命令示例: ```bash netstat -ntlp | grep -E '80|9999' ``` 使用 `ss` 命令示例: ```bash ss -tuln | grep -E '80|9999' ``` 如果发现端口被其他程序占用,可停止该程序或修改 Nginx 配置文件中的监听端口。 ### 修改 Nginx 配置文件监听端口 编辑 Nginx 配置文件 `/etc/nginx/nginx.conf` 或相关的虚拟主机配置文件,将监听端口修改为未被占用的端口。例如,将 `listen 80;` 和 `listen 9999;` 修改为其他端口: ```nginx server { listen 8080; listen 10000; server_name example.com; # 其他配置项 } ``` 修改完成后,使用 `nginx -t` 命令检查配置文件语法是否正确: ```bash nginx -t ``` 若语法检查通过,使用 `nginx -s reload` 命令重新加载配置: ```bash nginx -s reload ``` ### 检查 SELinux 和防火墙设置 SELinux 或防火墙可能会阻止 Nginx 正常绑定端口。可临时关闭 SELinux 或调整防火墙规则。 临时关闭 SELinux 示例: ```bash setenforce 0 ``` 开放防火墙端口示例(以 Firewalld 为例): ```bash firewall-cmd --permanent --add-port=8080/tcp firewall-cmd --permanent --add-port=10000/tcp firewall-cmd --reload ``` ### 检查 Nginx 服务状态 使用 `systemctl restart nginx` 命令重启 Nginx 服务,然后使用 `systemctl is-active nginx` 检查服务是否正常运行: ```bash systemctl restart nginx systemctl is-active nginx ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值