Nginx fails to stop and nginx.pid is missing

Solution 1:

I will recommend stopping nginx by killing it's master process first. The nginx is not shutdown properly may be because of that it can't be stopped using init script.

ps -ef |grep nginx

This will show you the PID of nginx master process. Like you mentioned above:

root 19506 1 0 2013 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

Kill it using

kill -9 19506

Verify once again whether there is any nginx process running or port 80 is occupied. If you see any process is bind to port 80, Identify the PID and check if it can be killed.

ps -ef |grep nginx

netstat -tulpn |grep 80

make sure the filesystem is fine and you can read/write to /var file system. Then Start nginx

service nginx start

Solution 2:

Problem

For me the pid file name was different in those two files:

  • /usr/lib/systemd/system/nginx.service
    • pid /var/run/nginx.pid;
  • /etc/nginx/nginx.conf
    • PIDFile=/run/nginx.pid

Those two need to match.

Fix:

So I adjusted it in /usr/lib/systemd/system/nginx.service and then did:

systemctl daemon-reload
systemctl start nginx

Then it came up correctly.


Solution 3:

I had this problem, and running ps -ef | grep nginx would show me workers that would keep spinning up, despite killing the master process as suggested by the accepted answer:

[~]# ps -ef | grep nginx
nginx    10730     1  0 Sep14 ?        00:00:16 nginx: cache manager process            
nginx    18469     1  0 Oct09 ?        00:11:02 nginx: worker process                   
nginx    25779     1  0 Oct13 ?        00:01:31 nginx: worker process                   
nginx    26458     1  0 15:45 ?        00:00:00 nginx: worker process    

So my solution to fix it was simply this: pkill nginx && service nginx restart

Tags:

Nginx

Centos