Nginx Invalid PID number

Nginx

Nginx Problem Overview


I issued a nginx -s stop and after that I got this error when trying to reload it.

>[error]: invalid PID number "" in "/var/run/nginx.pid"

That /var/run/nginx/pid file is empty atm.

What do I need to do to fix it?

Nginx Solutions


Solution 1 - Nginx

nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don't have a running nginx process to send a signal to. Just run nginx (possibly with a -c /path/to/config/file)

Solution 2 - Nginx

in my case I solved this by starting the service.

sudo /etc/init.d/nginx start

The command above will start the service in Debian/Ubuntu. It will issue an error if there is any problem (like Apache listening in the same port)

After that nginx -s reload will work like a charm

Solution 3 - Nginx

This will clear out the issue on ubuntu 16.04 and above

sudo service nginx stop    

you may need to remove the pid file nginx.pid whose location may be defined in file /etc/nginx/nginx.conf look for line like

cat /etc/nginx/nginx.conf | grep pid  #  see if pid file is defined

this line may live in file /etc/nginx/nginx.conf

pid /run/nginx.pid;  #  in file /etc/nginx/nginx.conf

if pid file does exist then remove it now

ls -la  /var/run/nginx/pid  #  this file may live elsewhere
ls -la  /run/nginx.pid  #  on Ubuntu 16.04+

after the pid file has been removed lets launch nginx

sudo service nginx start

ps -eaf|grep nginx        #  confirm its running

sudo nginx -t && sudo nginx -s reload   #  confirm config is OK

#      typical output
#  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
#  nginx: configuration file /etc/nginx/nginx.conf test is successful


sudo service nginx stop   #   issue stop

ps -eaf|grep nginx        #   confirm it actually stopped

now sanity has been restored and you are free to launch at will

Solution 4 - Nginx

In the latest version(1.2.0) that I downloaded there is no "-s start" option, it will say nginx: invalid option: "-s start"

You can start nginx by

sudo /etc/nginx/sbin/nginx

The server will be started and then there wont be any Invalid pid number errors.

Solution 5 - Nginx

To avoid downtime with restarting nginx,

ps aux | grep nginx 
PID of nginx master process

echo PID > /var/run/nginx.pid
nginx -s reload

Solution 6 - Nginx

In my case nginx was stopped (crashed I assume). Solved the issue by:

service nginx status
nginx stop/waiting

service nginx start
nginx start/running, process 3535

Then nginx -s reload worked like a charm.

I am using nginx/1.8.0 on trusty.

Solution 7 - Nginx

On CentOS 7 I done it with this:

 sudo systemctl start nginx
 #Then check all things are OK
 sudo systemctl status -l nginx

Solution 8 - Nginx

This happens if the nginx process was stopped manually or was killed.

Check if the process is still running:

sudo lsof -nP -iTCP:<port> | grep LISTEN

I am on mac, and I reinstall the nginx with:

brew reinstall nginx

Then start the service using brew:

brew services start nginx

Solution 9 - Nginx

For anyone who still has issues, in my case, there was an apache2 server that was running. You can try debugging what went wrong in your nginx machine by executing this command - systemctl status nginx This gave me an insight that the port was already in us by apache2 server. so you can do sudo service apache2 stop and then do sudo service nginx start.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHarryView Question on Stackoverflow
Solution 1 - NginxkolbyjackView Answer on Stackoverflow
Solution 2 - NginxAdrián DeccicoView Answer on Stackoverflow
Solution 3 - NginxScott StenslandView Answer on Stackoverflow
Solution 4 - Nginxblogme4uView Answer on Stackoverflow
Solution 5 - Nginxb3nkyView Answer on Stackoverflow
Solution 6 - NginxramonamisView Answer on Stackoverflow
Solution 7 - NginxLANKOANDE YaboView Answer on Stackoverflow
Solution 8 - NginxVishrantView Answer on Stackoverflow
Solution 9 - NginxKKMView Answer on Stackoverflow