Tag Archives: CreateFile() “xxx/logs/nginx.pid” failed

Troubleshooting of nginx error under Windows: createfile() “XXX / logs / nginx. PID” failed

 

phenomenon

Under windows, when we execute nginx -s stop or Nginx -s quit  or Nginx -s reload   You may receive the following error messages:

nginx: [error] CreateFile() "D:/software/nginx/logs/nginx.pid" failed (2: The system cannot find the file specified)

analysis

When we use start Nginx   To start Nginx xxx/logs/   Generated under the directory named   Nginx.PID   The content of the file has only one number, that is, the PID corresponding to the nginx.exe process. Whether stop, quit or reload, you need to use the PID of nginx.exe to operate it. However, in some special cases (we will create a special case artificially below), Nginx.PID will be lost, so the above three commands will report an error because Nginx.PID cannot be found. Obviously, it is impossible to stop, quit or reload successfully at this time, because nginx doesn’t even know which process it corresponds to.

Solution:

Simple and rough: 1) pass tasklist | findstr “nginx.exe”   Find out the PID corresponding to nginx.exe; 2) In xxx/logs/   New text file under Nginx.pid  , Write the PID of the previous step through the text editor (of course, this step can also be carried out through command line, script, hands-on programming and other methods that can achieve the purpose); 3) Execute Nginx -s stop or Nginx -s quit   Or Nginx -s reload.

verification

[required]

In this verification, the nginx installation path is   D:/software/nginx  , The listening port is 5000.

The rendering method is a command-line screenshot. The commands used will be given in the form of text in the back, which is convenient for readers to copy and paste.

This paper only focuses on the problem of “unable to find nginx. PID”. For other problems derived from the verification process, this paper only gives the link of the answer and does not guarantee the right remedy (it does not mean that the document content is wrong, but does not guarantee that the corresponding problem can be solved). I also urge readers who know the answer to give me advice.

The commands in the verification process must be executed under the nginx installation directory, otherwise an error will occur. If you have to execute in any directory, please refer to another blog under. At the same time, remember to make corresponding changes to the relevant path.

The verification process is shown in the figure below:

Verification process

The commands used are sorted as follows:

1 start nginx
2 tasklist | findstr "nginx.exe"
3 netstat -ano | findstr "5000"   
4 type ./logs/nginx.pid
5 nginx -s quit
6 cmd /r dir /b .\\logs
7 13632 | Out-File -Encoding ASCII ./logs/nginx.pid