9

My nginx was compile from the source, only give the flag that --conf-path=/etc/nginx/nginx.conf

Everything works and I was trying to use this service init.d script to make nginx as a system service,

Here's the script that I made only 2 minor changes:

1. DAEMON=/usr/local/nginx/sbin/nginx

2.NGINX_CONF_FILE="/etc/nginx/nginx.conf"

then sudo service nginx start

it works

yozloy@SNDA-172-17-10-158:/usr/local$ sudo service nginx start
 * Starting Nginx Server...
   ...done

.

but service nginx stop and service nginx reload

give me a error

yozloy@SNDA-172-17-10-158:/usr/local$ sudo service nginx stop
 * Stopping Nginx Server...
   ...fail!

and the error doesn't appear on the log/error.log file

mko
  • 21,334
  • 49
  • 130
  • 191

1 Answers1

20

I've had similar problems with Nginx on Ubuntu 12.04, with nginx compile from source and init script taken from a similar source as yours.

Service started well with the init file, but stop or restart didn't. In the end the cause was a different path to the pid file in the nginx.conf and the init script. Make sure they both point to the same location.

capsized
  • 316
  • 2
  • 3
  • thanks for answer.I've been waiting for a long time. Could you explain more details to do that which let them point to a same location? – mko Jul 23 '12 at 22:06
  • 3
    @yozloy in your nginx.conf file, you find the line "pid /tmp/nginx.pid;" you should use that directory and change the init scripts location of the pid file for each action in your init script. – Philip Oct 08 '12 at 09:38
  • For situations where the stopping/restarting fails intermittently (often deletes the PID file, but the processes including master won't die), see [this answer](http://unix.stackexchange.com/questions/119037/why-doesnt-stopping-the-nginx-server-kill-the-processes-associated-with-it). – Ville Dec 30 '15 at 06:30