重启nginx后丢失nginx.pid,如何重新启动nginx

Submitted by phifans on Tue, 12/20/2022 - 17:56

在使用的阿里云服务器上,进程性的 nginx -s stop后再次启动nginx -s reload ,总是会报错误nginx: [error] open() "/alidata/server/nginx/logs/nginx.pid" failed (2: No such file or directory),这应该是因为把nginx进程杀死后pid丢失了,下一次再开启nginx -s reload时无法启动,重装可以解决这个问题,但是太麻烦了。

用google开始搜索英文网站上解决方法如下:
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)

于是我用了这方法,也就是nginx -c /path/to/config/file) //在我机器上是这样的/alidata/server/nginx/sbin/nginx -c /alidata/server/nginx/conf/nginx.conf

希望可以帮助到大家。

栏目