ERROR : invalid PID number "" in "/run/nginx.pid"

Viewed 24773

My nginx is not starting on 80 port.

I have added the following details:

$ nginx -s reload
2016/03/23 16:11:27 [error] 24992#0: invalid PID number "" in "/run/nginx.pid"
$ ps -ef | grep nginx
root     25057  2840  0 16:16 pts/1    00:00:00 grep --color=auto nginx
$ kill -9 25057
bash: kill: (25057) - No such process
$ service nginx start
Nothing..

Please provide solution..

4 Answers

Let's talk about what we have here first:

$ nginx -s reload
2016/03/23 16:11:27 [error] 24992#0: invalid PID number "" in "/run/nginx.pid"

It's probably because the /run/nginx.pid file is empty, that causes issues with stop|start|restart commands, so you have to edit it by sudo and put there PID of your current running nginx service (master process). Now, let's have a look at the next lines, which are connected with.

$ ps -ef | grep nginx
root     25057  2840  0 16:16 pts/1    00:00:00 grep --color=auto nginx
$ kill -9 25057
bash: kill: (25057) - No such process

You're trying here to kill NOT a main process of the nginx. First try to run the following command to see the pids of an nginx master process and his worker:

$ ps -aux | grep "nginx"
root     17711  0.0  0.3 126416  6632 ?        Ss   18:29   0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
www-data 17857  0.0  0.2 126732  5588 ?        S    18:32   0:00 nginx: worker process
ubuntu   18264  0.0  0.0  12916   984 pts/0    S+   18:51   0:00 grep --color=auto nginx

Next, kill both:

$ sudo kill -9 17711
$ sudo kill -9 17857

and then try to run an nginx again.

$ service nginx start
Nothing..

Have nothing to say here ;)

Summary:

I think editing the /run/nginx.pid file with an nginx master process PID should solve the issue. So according to my example above, this file should looks like this:

17711

Hope that helps!

I have this problem. I restart the nginx.service and it fixed.

Run sudo systemctl restart nginx.service and then run sudo nginx -s reload in ubuntu.

ps -ef | grep nginx | grep root | grep -v grep | awk '{ print $2 }' > /run/nginx.pid

nginx -s reload

Related