Many people are accustomed to start a Nginx web server through init scripts and then they can control the state of the server through service
command, such as sudo service nginx restart
. But sometimes unobvious config error makes the scripts failed to work. Here I will show an error related to pid
directive in the config file of nginx, which defaultly located at /opt/nginx/conf/nginx.conf
. As ignored by many people, some init scripts assump there is a pid file of nginx located at /var/run/nginx.pid
, but in the fact, the default pid file for nginx is /opt/nginx/logs/nginx.pid
. Because the scripts can’t get the correct pid or even get nothing, they failed to stop the nginx process, some tasks dependent on it will be failed too, for example, you are not able to restart the server.
To resolve this problem, you need to:
$ sudo service nginx destroy
$ sudo vim /opt/nginx/conf/nginx.conf
# /opt/nginx/conf/nginx.conf
pid /var/run/nginx.pid
$ sudo service nginx start
service
command:$ cat /var/run/nginx.pid
$ sudo service nginx restart
As expected, you will see the screen out “OK” for your operations.