开发者

Nginx Invalid PID number

开发者 https://www.devze.com 2023-04-10 06:19 出处:网络
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\"

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


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


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


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.


To avoid downtime with restarting nginx,

ps aux | grep nginx 
PID of nginx master process

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


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.


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


On CentOS 7 I done it with this:

 sudo systemctl start nginx
 #Then check all things are OK
 sudo systemctl status -l 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.


Docker Alpine users should use

nginx

by using that nginx will be start there is no error by

nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

then reload it by

nginx -s reload

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号