问题描述
执行nginx -s reload
时,出现如下错误
[root@iZuf65h6i43ltlzhqolumyZ conf]# ../sbin/nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
解决办法
因为每一个nginx
进程都对应一个id
,存放于nginx.pid
中,而在进行重新编译时可能会因为一些bug
导致nginx.pid
中的id
号被卡死,因此无法重启。想要解决这个问题可以杀掉所有nginx
进程,再用-c
命令指定配置文件进行启动。
【1】执行命令killall -9 nginx
杀掉nginx
进程;
[root@iZuf65h6i43ltlzhqolumyZ conf]# killall -9 nginx
【2】指定配置文件-c
启动nginx
[root@iZuf65h6i43ltlzhqolumyZ sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf
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()
如果如下出现failed
表示nginx
卡死了,我们需要通过如下命令查看nginx
占用的端口。
[root@iZuf65h6i43ltlzhqolumyZ sbin]# sudo netstat -tulpn
直接给他关闭掉
kill -s 9 对应的pid
【3】进入/usr/local/nginx/sbin
执行命令./nginx -s reload
重新启动nginx
;
[root@iZuf65h6i43ltlzhqolumyZ sbin]# ./sbin/nginx -s reload