Create Nginx scripts under Linux-start, stop, Reload...,nginx-start
1. Close Nginx
Using Ps-aux | grep nginx to see if Nginx is started and kill if activated.
2. Create a/etc/init.d/nginx file
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/nginxroot@dnnp:~/software/nginx-1.2.3#/etc/init.d/nginx Startstarting nginx:nginx.root@dnnp:~/software/nginx-1.2.3# Ps-aux | grep Nginxwarning:bad PS syntax, perhaps a bogus '-'? See Http://procps.sf.net/faq.htmlroot 25078 0.0 0.0 4596 ? Ss 14:20 0:00 nginx:master process/usr/local/nginx/sbin/nginxnobody 25079 0.0 0.1 4820 1056? S 14:20 0:00 nginx:worker processroot 25081 0.0 0.0 3304 768 pts/0 s+ 14:20 0:00 grep nginxroot@dnnp:~/software/nginx-1.2.3#
Note: The contents of the/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 AA default-stop:0 1 6# short-description:starts the Nginx Web server# description:starts nginx using Start-stop-daemo n### END INIT INFO path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bindaemon=/usr/local/nginx/sbin/ Nginxname=nginxdesc=nginx Test-x $DAEMON | | Exit 0 # Include Nginx defaults if Availableif [-f/etc/default/nginx]; Then. /etc/default/nginx#. /usr/local/nginx/conffi set-e. /lib/lsb/init-functions case "$" in start) echo-n "Starting $DESC:" Start-stop-daemon--start--quiet--pidfile/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 \--exec $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--$DAEMON _ OPTS | | True echo "$NAME." ;; Reload) echo-n "Reloading $DESC configuration:" Start-stop-daemon--stop--signal HUP--quiet--pidfile/usr/local/n ginx/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
How to restart Nginx under Linux
In the early version of Nginx, Nginx reboot requires the KILL command to send a signal to Nginx to implement the Nginx reboot.
However, now, Nginx added the-s option to implement Nginx stop, reload function.
1. If it is a smooth restart Nginx, you can use the./nginx-s reload command to achieve a smooth restart of nginx.
2. If the non-smooth restart, you can stop the Nginx before starting:
./nginx-s stop &&./nginx
When we modify the Nginx configuration, we want to restart Nginx for the nginx to take effect, at this time in order to ensure that nginx in the restart phase can also provide normal service, generally using a smooth restart (reload) restart Nginx. At this point, Nginx loads the new configuration and then fork out the new worker process. At the same time, the master process sends a signal to the old worker process to tell the old worker process the current situation. After the old worker process is signaled by the master process, if the request is not processed then it exits, and if the request is being processed, the old worker process finishes processing the request and exits. Nginx is this way to reload the new configuration, so that in the process of restarting, can still provide services.
Restart Nginx, the command appears, and then enter what command
Start start service Stop stop service reload reread configure restart restart service
http://www.bkjia.com/PHPjc/856991.html www.bkjia.com true http://www.bkjia.com/PHPjc/856991.html techarticle create Nginx scripts under Linux-start, stop, Reload...,nginx-start 1, off Nginx using Ps-aux | grep nginx to see if Nginx is started if Kill kills 2, create/etc/ Init ...