解决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的时候报错:

| 1 | nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory) |
看信息是提示
logs/nginx.pid
文件不存在,去目录下看了一下,确实没有。
解决方法
使用
nginx -c
的参数指定
nginx.conf
文件的位置。那这个
nginx.conf
文件在哪呢?可以使用
nginx -t
得到。如下:
| 1 2 3 4 5 | $ 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 $ /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf |
再看一下
logs
目录,
nginx.pid
文件已经有了。这时候再重启成功。
| 1 | nginx -s reload |
nginx: [error] invalid PID number
在上边的过程中,你也许会出现这个错误,nginx
PID
丢失。

解决方法是一样的,用
-c
选项指定
nginx.conf
就可解决。
| 1 | nginx -c /usr/local/nginx/conf/nginx.conf |
还是无法解决?
如果你使用以上方法都无法解决,如图:

也有可能是其它错误信息,但不要管,按以面的顺序解决:
- 使用
nginx -t检查配置是否正确,你也可以使用-t指定配置文件如:nginx -t /usr/local/nginx/conf/site1.conf,如果有错误检查并修复,直至没错继续; - 强制关闭nginx,使用命令:
ps -ef | grep nginx找到master主进程号; - 使用强制停止命令:
kill -QUIT master主进程号; - 开启nginx