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.