nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed
重启nginx的时候报错:
![解决nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)](https://asset.appfiles.xyz/d/file/20200322/2c97cc5531e18bcad9645f1c63e6728d.png)
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得到。如下:
$ 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文件已经有了。这时候再重启成功。
nginx -s reload
nginx: [error] invalid PID number
在上边的过程中,你也许会出现这个错误,nginx PID丢失。
![解决nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)](https://asset.appfiles.xyz/d/file/20200322/74a7407472b026c483c0c85a031f4e4a.png)
解决方法是一样的,用-c选项指定nginx.conf就可解决。
还是无法解决?
如果你使用以上方法都无法解决,如图:
![解决nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)](https://asset.appfiles.xyz/d/file/20200322/91011f7620296881aa280ff8ebe0d5c6.png)
也有可能是其它错误信息,但不要管,按以面的顺序解决:
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

