1. Close Nginx
Using Ps-aux | grep Nginx See if the nginx is started and kill if it starts.
2. Create/etc/init.d/nginx files
root@dnnp:~/software/nginx-1.2.3# Vim/etc/init.d/nginx
3, add permissions and start
root@dnnp:~/software/nginx-1.2.3# chmod +x/etc/init.d/nginx
root@dnnp:~/software/nginx-1.2.3#/etc/init.d/ Nginx start
starting Nginx:nginx.
root@dnnp:~/software/nginx-1.2.3# Ps-aux | grep nginx
Warning:bad PS syntax, perhaps a bogus '-'? http://procps.sf.net/faq.html
root 25078 0.0 0.0 4596 ? Ss 14:20 0:00 nginx:master process/usr/local/nginx/sbin/nginx
Nobody 25079 0.0 0.1 4820 1056? S 14:20 0:00 nginx:worker process
root 25081 0.0 0.0 3304 768 pts/0 s+ 14:20 0:00 grep nginx
root@dnnp:~/software/nginx-1.2.3#
Note: The contents of/etc/init.d/nginx file are as follows
#! /bin/sh ### BEGIN INIT INFO # provides:nginx # Required-start: $all # required-stop: $all # default-start:2 3 4 5 # default-stop:0 1 6 # Short-description:starts the Nginx Web server # description:starts Nginx using Start-s Top-daemon ### End INIT INFO path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/local/ Nginx/sbin/nginx name=nginx desc=nginx test-x $DAEMON | | Exit 0 # Include Nginx defaults if available if [-f/etc/default/nginx]; Then. /etc/default/nginx #. /usr/local/nginx/conf fi set-e. /lib/lsb/init-functions case "in Start" Echo-n "Starting $DESC:" Start-stop-daemon--start--quiet /usr/local/nginx/logs/$NAME. PID \--exec $DAEMON--$DAEMON _opts | |
True echo "$NAME."
;; Stop) echo-n "stopping $DESC:" Start-stop-daemon--stop--quiet--pidfile/usr/local/nginx/logs/$NAME. PID \--ex EC $DAEMON | |
True echo "$NAME."
;; Restart|force-reload) echo-n "RestartinG $DESC: "Start-stop-daemon--stop--quiet--pidfile \/usr/local/nginx/logs/$NAME. PID--exec $DAEMON | | True sleep 1 Start-stop-daemon--start--quiet--pidfile \/usr/local/nginx/logs/$NAME. PID--exec $DAEMON--$DAEM on_opts | |
True echo "$NAME."
;; Reload) echo-n "reloading $DESC configuration Start-stop-daemon--stop--signal HUP--quiet /nginx/logs/$NAME. pid \--exec $DAEMON | |
True echo "$NAME."
;; Status) status_of_proc-p/usr/local/nginx/logs/$NAME. pid "$DAEMON" Nginx && exit 0 | |
Exit $?
;;
*) n=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 exit 1;;
ESAC Exit 0