部署flask项目,添加配置文件后,想重启一下nginx,结果报错:
$ sudo nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
原因分析:
nginx.pid丢掉了
解决:
issued a nginx -s stop and after that I got this error when trying to reload it.
[error]: invalid PID number “” in “/var/run/nginx.pid”
That /var/run/nginx/pid file is empty atm.
What do I need to do to fix it?
nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don't have a running nginx process to send a signal to. Just run nginx (possibly with a -c /path/to/config/file)
运行命令,问题得以解决:
sudo /usr/sbin/nginx -c /etc/nginx/nginx.conf
$ sudo /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:8000 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:8090 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:2021 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8000 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:8090 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:2021 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8000 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:8090 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:2021 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8000 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:8090 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:2021 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8000 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:8090 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:2021 failed (98: Address already in use)
nginx: [emerg] still could not bind()
$ sudo /usr/sbin/nginx -s reload
$ ps -ef | grep nginx
root 23072 1 0 14:47 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
root 24923 23072 0 14:50 ? 00:00:00 nginx: worker process
root 24924 23072 0 14:50 ? 00:00:00 nginx: worker process
root 24925 23072 0 14:50 ? 00:00:00 nginx: worker process
root 24926 23072 0 14:50 ? 00:00:00 nginx: worker process
root 24927 23072 0 14:50 ? 00:00:00 nginx: worker process
root 24928 23072 0 14:50 ? 00:00:00 nginx: worker process
606 25538 4063 0 14:50 pts/8 00:00:00 grep nginx
参考:https://www.jb51.net/article/45658.htm