Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

bash

nginx

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..

like image 987
aksy91 Avatar asked Mar 23 '16 10:03

aksy91


3 Answers

Trying to run nginx -s reload without first starting nginx will result in an error because nginx will look for the file containing it's master pid when you tell it to restart. In your case it seems that nginx wasn't running, so the file containing that id doesn't exist.

By running kill -9 25057 you tried to kill your own command ps -ef | grep nginx which no longer existed, so you got "No such process".

To make sure all is well I would stop nginx with nginx -s stop then start it with nginx followed by nginx -s reload to check that all is well. In any case the log file might tell you if something bad is going on /var/log/nginx/error.log.

If that works, you can try accessing http://localhost:80 or however you have configured nginx, and also follow the error log, and access log /var/log/nginx/error.log

As a sidenote: If this by any chance happens to be a case where nginx is reloaded by some other tool like confd, you should also check if nginx actually stores it's pid in /run/nginx.pid as opposed to /var/run/nginx/nginx.pid.

like image 120
brujoand Avatar answered Nov 09 '22 02:11

brujoand


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!

like image 34
turkus Avatar answered Nov 09 '22 01:11

turkus


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.

like image 1
Mohammadmain Yaghoobi Avatar answered Nov 09 '22 02:11

Mohammadmain Yaghoobi