/var/run/nginx/nginx.pid” failed (2: No such file or directory)

The nginx server keeps reporting the following error when the server is shut down and restarted:

[root@localhost sbin]# nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

Solution:

    /> /local/nginx/conf/

     cd /usr/local/nginx/conf/
    
      Edit the configuration file nginx.conf
    vi nginx.conf
    
      The following code is commented in the configuration file:
    #pid   logs/nginx.pid;
    
      removes the comment, i.e. #, and changes it to the following code:
    pid    /usr/local/nginx/logs/nginx.pid;
    
      Press ESC, enter the following code, save and exit
    :wq
    
      > create logs directory in /usr/local/nginx:
    [root@localhost conf]# mkdir /usr/local/nginx/logs
    
      Start the nginx service:
    /usr/local/nginx/sbin/nginx
    

    Pro test successful!

Read More: