Nginx解决Address already in use以及invalid PID number错误

服务器重启之后导致nginx服务无法正场开启,导致网页打不开。
重新启动该服务提示:

Starting 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()

地址已经被占用,导致端口占用,出现此错误,查看端口:

[root@localhost /]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name    
tcp        0      0 :::80                       :::*                        LISTEN      4279/nginx    
.....

直接杀掉进行,准备重新启动:

kill -9 4279

再次启动:

/usr/local/nginx/sbin/nginx -s reload

出现如下错误:(一时间也很奔溃)

nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

去提示的目录查找确实不存在这个文件,判定nginx未正常启动造成的,读取的配置文件不正确,重新指定配置文件

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

再次提示端口被占用,查看端口使用情况

[root@localhost /]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name    
tcp        0      0 :::80                       :::*                        LISTEN      4280/nginx    
.....

问题分析:应该是nginx自动关闭启动,进程杀死之后会再次自动启动
解决方案:杀死之后立马手动启动

kill -9 4280 &&  /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

问题解决,mark一下~

发布了67 篇原创文章 · 获赞 46 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/Fouse_/article/details/90414277