Nginx start, close, and reload the script, and nginx start and load the script
#! /bin/sh# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts the nginx web serverPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDESC="nginx daemon"NAME=nginxDAEMON=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/$NAME.confPIDFILE=/usr/local/nginx/logs/$NAME.pidSCRIPTNAME=/etc/init.d/$NAMEset -e[ -x "$DAEMON" ] || exit 0do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running"}do_stop() { kill -INT `cat $PIDFILE` || echo -n "nginx not running"}do_reload() { kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"}case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;;esacexit 0
Note: You must modify the text in red based on the actual path. Name the script nginx and save it to the/etc/init. d directory. If you try the/etc/init. d/nginx start command, the error "permission is insufficient" will be reported. Run chmod + x/etc/init. d/nginx to grant it the execution permission.
You can execute this script in the following way:
/Etc/init. d/nginx start
/Etc/init. d/nginx sttop
/Etc/init. d/nginx reload
/Etc/init. d/nginx restart
Note the chkconfig xx command in the script header if you want to enable the script to start automatically after it is started (For details, refer to the chkconfig command usage ), make it support chckconfig and then execute the/sbin/chkconfig nginx on command. In addition, you can run sudo/sbin/chkconfig -- list nginx to view the effect.
How can I disable nginx startup?
Click Start on the computer and run msconfig to view the startup Item to disable nginx.
How to enable and disable nginx after a smooth restart
Assume that your nginx directory is/usr/opt/nginx/sbin/nginx. Assume that the nginx directory is/usr/opt/nginx/conf/www4.conf. the restart method is as follows: the/usr/opt/nginx/sbin/nginx-c/usr/opt/nginx/conf/www4.conf parameter-c specifies the path of the configuration file. If this parameter is not specified, nginx loads nginx under the conf directory of the directory by default. conf. smooth restart: 1. Check whether the modified configuration file is correct: /usr/opt/nginx/sbin/nginx-t-c/usr/opt/nginx/conf/www4.conf 2. kill-HUP Nginx master process number. Example: kill-HUP 'cat/usr/local/webserver/nginx/logs/nginx. pid:-c specifies a configuration file for Nginx to replace the default one. -T does not run, but only tests the configuration file.