Nginx无效的PID编号

Har*_*rry 37 nginx

我发出了一个nginx -s stop,之后我在尝试重新加载时遇到了这个错误.

[错误]:"/var/run/nginx.pid"中的PID编号""无效

/ var/run/nginx/pid文件为空atm.

我需要做些什么来解决它?

kol*_*ack 45

nginx -s reload仅用于告诉正在运行的nginx进程重新加载其配置.停止后,您没有运行nginx进程来发送信号.只需运行nginx(可能使用-c/path/to/config/file)

  • 在当前发行版的库存安装中,您可能希望使用启动脚本:`sudo service nginx start` (7认同)

Adr*_*ico 16

在我的情况下,我通过启动服务解决了这个问题.

sudo /etc/init.d/nginx开始

上面的命令将在Debian/Ubuntu中启动该服务.如果有任何问题(例如Apache在同一端口侦听),它将发出错误

之后,nginx -s reload将像魅力一样工作


小智 8

在我下载的最新版本(1.2.0)中没有"-s start"选项,它会说nginx:invalid选项:" - s start"

你可以通过启动nginx

sudo /etc/nginx/sbin/nginx
Run Code Online (Sandbox Code Playgroud)

服务器将启动,然后不会有任何无效的pid号错误.


Sco*_*and 7

这将清除 ubuntu 16.04 及更高版本的问题

sudo service nginx stop    
Run Code Online (Sandbox Code Playgroud)

您可能需要删除nginx.pid其位置可能在文件/etc/nginx/nginx.conf查找行中定义的 pid 文件,例如

cat /etc/nginx/nginx.conf | grep pid  #  see if pid file is defined
Run Code Online (Sandbox Code Playgroud)

这一行可能存在于文件中 /etc/nginx/nginx.conf

pid /run/nginx.pid;  #  in file /etc/nginx/nginx.conf
Run Code Online (Sandbox Code Playgroud)

如果pid文件确实存在,则立即将其删除

ls -la  /var/run/nginx/pid  #  this file may live elsewhere
ls -la  /run/nginx.pid  #  on Ubuntu 16.04+
Run Code Online (Sandbox Code Playgroud)

pid 文件被删除后,让我们启动 nginx

sudo service nginx start

ps -eaf|grep nginx        #  confirm its running

sudo nginx -t && sudo nginx -s reload   #  confirm config is OK

#      typical output
#  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
#  nginx: configuration file /etc/nginx/nginx.conf test is successful


sudo service nginx stop   #   issue stop

ps -eaf|grep nginx        #   confirm it actually stopped
Run Code Online (Sandbox Code Playgroud)

现在理智已经恢复,你可以随意发射


小智 5

在我的情况下,nginx被停止了(我假设崩溃了).解决了这个问题:

service nginx status
nginx stop/waiting

service nginx start
nginx start/running, process 3535
Run Code Online (Sandbox Code Playgroud)

然后nginx -s reload就像魅力一样.

我在trusty上使用nginx/1.8.0.


小智 5

为了避免因重启Nginx而造成的停机,

ps aux | grep nginx 
PID of nginx master process

echo PID > /var/run/nginx.pid
nginx -s reload
Run Code Online (Sandbox Code Playgroud)