Production server:
OS: CentOS 6.8
1. Create a new nginx file in the directory "/etc/init.d" and add the following code.
[root@localhost init.d]# vi nginx
[root@localhost 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 is 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
)
[ $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 "$1" instart) start restart) Stop start ;;status) status $prog RETVAL=$? exit $ RETVAL2. Set up the startup service, save the /etc/init.d/nginx file, and execute the following command:[root@localhost init.d]# chmod 755 /etc/init.d/nginx #Give File execution permissions[root@localhost init.d]# chkconfig --add nginx[root@localhost init.d]# chkconfig --level 2345 nginx on #Set up startup3. nginx start, stop, Non-stop service restart[root@localhost /]# service nginx statusnginx (pid 1621 1619) is running...[root@localhost /]# service nginx stopStop nginx: [Confirmed][root@localhost /]# service nginx startStarting nginx: because