解决 重新加载nginx时nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

今天因为配置虚拟主机需要重新加载一便边nginx,于是/usr/local/sbin/nginx -s reload 

报错如下

[root@VM_0_3_centos sbin]# ./nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/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)

大概意思是说 ./nginx-s reload 命令只是给一正在运行的nginx程序发送一个加载的重新加载配置的信号,但是当你的nginx程序由于某种原因被杀死的话也就没有程序能否接受以及启动了,只需要在启动命令-c可能需要加上配置文件路径

照做之后如下

[root@VM_0_3_centos sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf
[root@VM_0_3_centos sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@VM_0_3_centos sbin]# ./nginx -s reload

测试和重载都没有问题,问题解决。

接着为了查明真相,查看nginx命令

[root@VM_0_3_centos sbin]# ./nginx -h
nginx version: nginx/1.16.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

发现-c是设置一下配置文件,也就是重新指定一下配置文件,于是我的猜测是那个被杀死的进程就是加载配置文件的进程,所以找不到PID等等的错误。(纯属本人瞎猜的)

猜你喜欢

转载自blog.csdn.net/weixin_44495941/article/details/105126102