Nginx Invalid PID number

Solution 1:

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:

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:

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:

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:

To avoid downtime with restarting nginx,

ps aux | grep nginx 
PID of nginx master process

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