解决nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)

nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed

重启nginx的时候报错:

解决nginx: [error] open()

看信息是提示 logs/nginx.pid 文件不存在,去目录下看了一下,确实没有。

解决方法

使用 nginx -c 的参数指定 nginx.conf 文件的位置。那这个 nginx.conf 文件在哪呢?可以使用 nginx -t 得到。如下:

再看一下 logs 目录, nginx.pid 文件已经有了。这时候再重启成功。

nginx: [error] invalid PID number

在上边的过程中,你也许会出现这个错误,nginx PID 丢失。

解决nginx: [error] open()

解决方法是一样的,用 -c 选项指定 nginx.conf 就可解决。

还是无法解决?

如果你使用以上方法都无法解决,如图:

解决nginx: [error] open()

也有可能是其它错误信息,但不要管,按以面的顺序解决:

  1. 使用 nginx -t 检查配置是否正确,你也可以使用 -t 指定配置文件如: nginx -t /usr/local/nginx/conf/site1.conf ,如果有错误检查并修复,直至没错继续;
  2. 强制关闭nginx,使用命令: ps -ef | grep nginx 找到 master主进程号
  3. 使用强制停止命令: kill -QUIT master主进程号
  4. 开启nginx