nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 原因与解决办法

Nginx是一款轻量级的Web服务器,特点是占有内存少,并发能力强,因而使用比较广泛,今天在一个VPS上重启Nginx时提示错误:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)

中文翻译

nginx:[emerg] bind()到0.0.0.0:80失败(98:地址已经在使用中)

nginx:[emerg] bind()到0.0.0.0:443失败(98:地址已经在使用中)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

 

原因

主要原因是:绑定80端口、443端口失败,端口已经在使用中。意思是端口已经存在,被占用了。

 

解决办法

那么:如何解决Nginx重启时提示“nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)”错误?

 

首先我们要弄清楚错误的原因是什么?

从上图中的报错,可以很清楚的得到这样一个原因,此错误指的是80端口被程序占用了。那么解决方法就简单了:

 

1、首先用命令:“lsof -i:80”查看端口被什么程序占用?

lsof -i:80

netstat -ntpl

 

 

2、关闭单干占用端口,命令:

[root@localhost conf]# pkill -9 nginx

kill -9 PID(例如:kill -9 1688)

 

也可以用:

强制关闭端口的占用,一个简单的命令就解决了。

sudo fuser -k 80/tcp #关闭占用80端口的程序

 

使用效果示例:

[root@198.162.1.122 ~]# sudo fuser -k 80/tcp
80/tcp:               2010  2019  2020  2021  2022  2023  2024  2028  2029

 

3、重新启动Nginx。

[root@localhost nginxssl]# ./sbin/nginx

 


 

今天我重启nginx的时候同样报错如下:

[root@localhost nginxssl]# ./sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] still could not bind()

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)

 

最终我才发现是我的修改nginx配置,我又忘记杀掉nginx进程。为了让配置生效,我是直接启动的nginx,没有重启或加载配置。

既然这样,我就杀掉nginx进程,再重启就可以恢复正常了。

    A+
发布日期:2019年03月14日 20:02:42  所属分类:Nginx
最后更新时间:2023-04-06 18:50:54
头像
  • ¥ 68.0元
  • 市场价:168.0元
  • ¥ 199.0元
  • 市场价:179.0元
  • ¥ 1.0元
  • 市场价:9.9元
  • ¥ 6.8元
  • 市场价:8.8元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: