The configuration file is based in the oficial nginx file, but modified to allow restarts (*)
# nginx description "nginx http daemon" author "George Shammas--- (*) Without the post-stop script, nginx didnt kill the forked processed and spit a 502 Bad Gateway . #you can see taht children are not killed after a `service nginx stop` sudo netstat -tulpn #to kill stalled children sudo fuser -k 80/tcp" start on (filesystem and net-device-up IFACE=lo) stop on runlevel [!2345] env DAEMON=/usr/sbin/nginx env PID=/var/run/nginx.pid expect fork respawn respawn limit 10 5 pre-start script $DAEMON -t if [ $? -ne 0 ] then exit $? fi end script # Ensure nginx is shutdown gracefully # Upstart will be tracking the wrong PID so the following is needed to stop nginx post-stop exec start-stop-daemon --stop --pidfile $PID --name nginx --exec $DAEMON --signal QUIT exec $DAEMON -c /etc/nginx/conf/nginx.conf