nginx: [error] CreateFile() “D:\nginx-1.20.1/logs/nginx.pid“ failed (2: The system cannot find the
下载解压完nginx后,双击nginx.exe后访问http://127.0.0.1/,能够出现欢迎界面
但是在命令行关闭nginx服务时(nginx -s quit),报错nginx: [error] CreateFile() “D:\nginx-1.20.1/logs/nginx.pid” failed
根据报错信息来看,在nginx安装目录下的logs文件中找不到nginx.pid文件,去对应文件查看,发现确实没有该文件
![nginx: [error] CreateFile() “D:\nginx-1.20.1/logs/nginx.pid“ failed (2: The system cannot find the_命令行](https://s2.51cto.com/images/blog/202112/22000232_61c1fa983b32537553.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
解决办法:
在任务管理器强制关闭nginx进程,
![nginx: [error] CreateFile() “D:\nginx-1.20.1/logs/nginx.pid“ failed (2: The system cannot find the_nginx_02](https://s2.51cto.com/images/blog/202112/22000232_61c1fa987581a12491.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
然后再在命令行中重新用start nginx命令启动,
![nginx: [error] CreateFile() “D:\nginx-1.20.1/logs/nginx.pid“ failed (2: The system cannot find the_nginx安装_03](https://s2.51cto.com/images/blog/202112/22000232_61c1fa98ad15098880.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
现在发现在nginx安装目录下的logs文件中出现了nginx.pid文件,
![nginx: [error] CreateFile() “D:\nginx-1.20.1/logs/nginx.pid“ failed (2: The system cannot find the_nginx_04](https://s2.51cto.com/images/blog/202112/22000233_61c1fa990275b68030.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
再用命令nginx -s quit正常关闭nginx进程,
![nginx: [error] CreateFile() “D:\nginx-1.20.1/logs/nginx.pid“ failed (2: The system cannot find the_命令行_05](https://s2.51cto.com/images/blog/202112/22000233_61c1fa995cafc5695.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
此时无法访问http://127.0.0.1/,成功关闭nginx
原因分析:
nginx在启动或重启时要杀掉之前的nginx进程,就需要通过nginx.pid来找到原来的进程,而nginx.pid存储的就是原来的进程id。没有进程id系统就无法找到原来的nginx进程,自然就无法关闭了
之后测试无论是双击nginx.exe还是cmd命令启动nginx,都会自动在logs文件下配置nginx.pid文件,均可正常关闭。不懂为啥第一次就不行呢?
为人:谦逊、激情、博学、审问、慎思、明辨、 笃行
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期

















