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

created at 09-01-2021 views: 119

error description

After modifying the nginx configuration file nginx.conf, if you want to restart nginx for the configuration to take effect. cmd to enter the nginx installation directory, enter the command: nginx -s reload,you will get the error:

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

problem track

  • The direct cause of the problem is that there is no nginx.pid file in the logs directory under the nginx installation directory. Under normal circumstances, the nginx.pid file is automatically created when nginx is started.
  • To start or restart nginx, the original nginx process needs to be killed, and the original process needs to be found according to nginx.pid. The pid is actually the original process ID.
  • The reason for this situation may be that nginx is not started or nginx.pid is manually deleted. Sometimes in the windows system by double-clicking to start nginx, it may not be able to automatically generate the nginx.pid file in the logs directory.
  • When nginx is not started (and you don’t know if it is started), do not use nginx -s reload command as the startup command to avoid this error.

solution

step1: Find the original nginx process (if any) in the task manager and close it, and then use the cmd command to start nginx

step2cmd to enter the nginx installation directory

step3: Enter the command start nginx or nginx.exe to start nginx

step4: Go to the /logs directory under the /nginx directory to see if there is a nginx.pid file; if not, repeat the 123 operation

step5: If nginx.pid has been generated, you can restart normally after modifying the configuration file

step6nginx -s reload

created at:09-01-2021
edited at: 06-06-2022: