问题
当启动nginx
时出现如下错误
[root@iZuf65h6i43ltlzhqolumyZ nginx]# ./sbin/nginxnginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)2024/02/17 13:18:36 [notice] 2828#0: signal process started2024/02/17 13:18:36 [error] 2828#0: open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
解决方案
【1】nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
问题可以通过创建logs
文件解决。
【2】nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
是因为nginx.conf
中的nginx.pid
被注释了,进入nginx.conf
目录编辑
[root@iZuf65h6i43ltlzhqolumyZ nginx]# vi conf/nginx.conf
将pid
的注释放开即可
pid logs/nginx.pid;
把注释取消掉,再重新启动Nginx
就OK
了
【3】没有指定配置目录:输入来使用指定nginx.conf
文件的方式重启nginx
(首先保证上面第一种情况的pid
没有被注释,否则可能前两次能打开,但是以后还是会报错的)
[root@iZuf65h6i43ltlzhqolumyZ nginx]# sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf