Follow this Blog!

Jul 21, 2015

f Comment

[SOLVED] Nginx Init Script STOP Command Not Working

Amazon Recently I had to build Nginx from source in order to integrate Google PageSpeed Module into Nginx. After I have done that, I went to https://github.com/JasonGiedymin/nginx-init-ubuntu/blob/master/nginx to get the nginx init.d Ubuntu script. The script can start Nginx successfully, but when I run this command to stop Nginx:
sudo service nginx stop
I get this error:
$ sudo service nginx stop
* Stopping Nginx Server...                            [fail]
How do I fix it?

I am running Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-43-generic x86_64). At the time of the writing the Nginx init.d Ubuntu script version is 3.9.0.


Reason

The reason this is happening might be because the Nginx's process ID's location specified by the new init script is different from the one specified by the old init script. In my case, the old PID file location is:
/run/nginx.pid
And the new PID file location is:
/usr/local/nginx/logs/nginx.pid

To find out the PID file location, look in the nginx init.d Ubuntu script.

When you run "sudo service nginx stop", your operating system actually deletes the process indicated by the PID file. Since your Nginx process is using the old PID file location, your new init script cannot delete the correct process.

Solution

1. Stop Nginx process. Suppose your old init script is located at /etc/init.d/nginx.original, then run this command:
sudo service nginx.original stop
Run the following command to make sure Nginx processes are gone:
ps aux | grep nginx
2. Go to Nginx configuration file (mine is located at /usr/local/nginx/conf/nginx.conf) and change the following line:
pid /run/nginx.pid;
To this line:
pid /usr/local/nginx/logs/nginx.pid;
3. Start Nginx again by running the following command and this problem should be fixed:
sudo service nginx start
Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
Find Michael on Google or Facebook
ADVERTISING WITH US - Direct your advertising requests to Michael