Production server:
OS : CentOS 6.8
1. in this directory "/ETC/INIT.D" Create a new Nginx file, add the following code.
[Email protected] init.d]# VI nginx
[email protected] init.d]# cat Nginx
#nginx Startup script for the Nginx HTTP Server
# It is v.0.0.2 version.
# Chkconfig:-85 15
# Description:nginx is a high-performance Web and proxy server.
# It has a lot of features, but it's not for everyone.
# Processname:nginx
# Pidfile:/var/run/nginx.pid
# config:/usr/local/nginx/conf/nginx.conf
Nginxd=/application/nginx/sbin/nginx
Nginx_config=/application/nginx/conf/nginx.conf
Nginx_pid=/var/run/nginx.pid
Retval=0
Prog= "Nginx"
# Source function library.
./etc/rc.d/init.d/functions
# Source Networking configuration.
./etc/sysconfig/network
# Check that networking are up.
[${networking} = "No"] && exit 0
[-X $nginxd] | | Exit 0
# Start Nginx daemons functions.
Start () {
If [-e $nginx _pid];then
echo "Nginx already running ..."
Exit 1
Fi
Echo-n $ "Starting $prog:"
Daemon $nginxd-C ${nginx_config}
Retval=$?
Echo
[$RETVAL = 0] && Touch/var/lock/subsys/nginx
Return $RETVAL
}
# Stop Nginx daemons functions.
Stop () {
Echo-n $ "Stopping $prog:"
Killproc $nginxd
Retval=$?
Echo
[$RETVAL = 0] && rm-f/var/lock/subsys/nginx/var/run/nginx.pid
}
# Reload Nginx service functions.
Reload () {
Echo-n $ "Reloading $prog:"
#kill-hup ' Cat ${nginx_pid} '
Killproc $nginxd-hup
Retval=$?
Echo
}
# See how we were called.
Case "$" in
Start
Start
;;
Stop
Stop
;;
Reload
Reload
;;
Restart
Stop
Start
;;
Status
Status $prog
Retval=$?
;;
*)
echo $ "Usage: $prog {start|stop|restart|reload|status|help}"
Exit 1
Esac
Exit $RETVAL
2. After setting up the boot service, save the/etc/init.d/nginx file, execute the following command:
[[email protected] init.d]# chmod 755/etc/init.d/nginx # give file execution permission
[Email protected] init.d]# chkconfig--add nginx
[[email protected] init.d]# chkconfig--level 2345 nginx on # set boot start
3 , Nginx Start, stop, non-disruptive service restart
[[Email protected]/]# service Nginx status
Nginx (PID 1621 1619) running ...
[[Email protected]/]# service Nginx stop
Stop nginx: [OK]
[[Email protected]/]# service Nginx start
Starting nginx: [OK]
[[Email protected]/]# service Nginx Reload
Re-loading nginx: [OK]
This article is from the "sky9890" blog, make sure to keep this source http://sky9896.blog.51cto.com/2330653/1878260
Nginx Boot automatically start service