启动nginx服务时出错,提示nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

来源:互联网 发布:米桶什么牌子好 知乎 编辑:程序博客网 时间:2024/06/01 08:25

  昨天做好的Lnmp架构,今天启动不了nginx服务,提示信息如下:

[root@wulinux ~]# service nginx start
正在启动 Nginx:nginx: [emerg] bind() to 0.0.0.0:80 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:80 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:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

  网查了下资料,说是nginx服务死掉了。说用lsof命令查看端口状态,然后kill掉服务。

  如果电脑上不识别lsof命令,要yum下。命令如下:

yun install -y lsof

  然后查看端口状态,我nginx服务用的是80端口。

lsof -i :80                 # -i 用以显示符合条件的进程情况

显示:

[root@wulinux ~]# lsof -i :80
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1173   root    6u  IPv4   9374      0t0  TCP *:http (LISTEN)
nginx   1174 nobody    6u  IPv4   9374      0t0  TCP *:http (LISTEN)


用kill杀掉进程, -9参数为强行中止

[root@wulinux ~]# kill -9 1173 
[root@wulinux ~]# kill -9 1174


然后重启nginx服务

[root@wulinux ~]# service nginx start
正在启动 Nginx:                                           [确定]


成功了,网页可以访问了。


后来发现一个问题,其实不像apache一样,每次开机都要重启服务(我的是这样的)。nginx配置后,是开机自动启动该服务的。








0 0
原创粉丝点击