Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx Invalid PID number

Tags:

nginx

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?

like image 872
Harry Avatar asked Oct 04 '11 11:10

Harry


6 Answers

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)

like image 161
kolbyjack Avatar answered Sep 26 '22 17:09

kolbyjack


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

like image 28
Adrián Deccico Avatar answered Sep 24 '22 17:09

Adrián Deccico


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

like image 31
Scott Stensland Avatar answered Sep 26 '22 17:09

Scott Stensland


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.

like image 31
blogme4u Avatar answered Sep 24 '22 17:09

blogme4u


To avoid downtime with restarting nginx,

ps aux | grep nginx 
PID of nginx master process

echo PID > /var/run/nginx.pid
nginx -s reload
like image 45
b3nky Avatar answered Sep 26 '22 17:09

b3nky


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.

like image 45
ramonamis Avatar answered Sep 24 '22 17:09

ramonamis