Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to stop Nginx but it fails like this.

$ sudo service nginx stop
Stopping nginx:                                            [FAILED]

And nginx.conf that defines place of have a line.

# /etc/nginx/nginx.conf
pid        /var/run/;

But there is no in the directory /var/run/.

locate shows this output.


But after updatedb there is no match for the search. I'm using nginx/1.4.4 in CentOS release 6.5 (Final).

What should I do to stop the nginx daemon?

Edit 2014/01/07

This is output of ps -ef | grep nginx, it seems nginx daemon is still running.

ironsand 17065 16933  0 15:55 pts/0    00:00:00 grep --color nginx
root     19506     1  0  2013 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
ironsand 19507 19506  0  2013 ?        00:00:25 nginx: worker process  

And sudo service nginx restart gives this error. I think nginx fails to start because old one still alive. And /var/log/nginx/error.log-2014017 contains also this error.

Stopping nginx:                                            [FAILED]
Starting nginx: nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] still could not bind()
share|improve this question
The system can't stop nginx if it isn't running and since there's no PID file, I suspect it is already stopped. You can check with ps -ef | grep nginx or sudo netstat -tlnp | grep nginx. – Ladadadada Jan 6 '14 at 16:18
Thanks for your advice. I added result of ps command. – ironsand Jan 7 '14 at 7:01
up vote 16 down vote accepted

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

share|improve this answer
Thanks! After killing master process, I had to kill also nginx worker process. Then I can finally start nginx daemon. – ironsand Jan 7 '14 at 7:56
You saved a soul just now Sandeep! Thanks a lot for documenting.. – Thale Aug 5 '14 at 23:58

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

share|improve this answer
This solution worked for me, thanks! – Himmel Apr 8 at 19:02

My problem was that I had pid specified in two different conf files. After I removed one reference then deleted the .pid file and started nginx again it started behaving normally.

share|improve this answer
Yep this one, the PID is defined in /usr/lib/systemd/system/nginx-debug.service and /etc/nginx/nginx.conf – edmondscommerce May 9 at 14:37

This seems to indicate that nginx is crashing immediately, if it had been started earlier. Have you checked the contents of /var/log/nginx* to see what the process is doing?

EDIT: Also, if you tell us your OS and version of nginx, we can give more detailed answers.

share|improve this answer
thanks, I just added more information. – ironsand Jan 7 '14 at 7:03

I'd need more information to be sure but, I'm guessing you already have another web server running rather than the instance of ngnix you want itself so you need to find it - the error says port 80 is in use, but not by what

Try netstat -tulpn - You're looking for an entry under local address that ends with :80 - this will also give you the program name and PID so you can identify it. Here's mine - I'm running lighttpd and its shown on the 3rd line.

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0*               LISTEN      4684/rtorrent
tcp        0      0*               LISTEN      923/php-fpm.conf)
tcp        0      0    *               LISTEN      972/lighttpd
tcp        0      0  *               LISTEN      4684/rtorrent
tcp        0      0    *               LISTEN      720/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      720/sshd
udp        0      0  *                           4684/rtorrent

Shut down the other web server properly (since if its spawning off upstart, a normal 'kill' may not work) and try starting ngnix. If thats the case, you can/should then edit your init scripts to stop the other web server from starting, or adjust its configuration on another power.

share|improve this answer
Thanks for your help. netstat -tulpn shows tcp 0 0* LISTEN 19507/nginx. So somehow nginx occupied that port. But as sandeep said, I killed nginx process then it works. I appreciate your help! – ironsand Jan 7 '14 at 8:00


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

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

Those two need to match.


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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.