生產伺服器:
OS:CentOS 6.8
1.在該目錄下」/etc/init.d」新建一個nginx文件,新增下列程式碼。
[root@localhost init.d]# vi nginx
[root@localhost init.d]# vi nginx[root@localhost init.d]# vi nginx
[root@localhost init.d]# vi nginx[root@localhost init.d]# cat nginx#nginx Startup script for the Nginx HTTP Server#nginx Startup script for the Nginx HTTP Server.
# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features, but it's not for # It has a lot of features, but it's not for . /var/run/nginx.pid# config: /usr/local/nginx/conf/nginx.confnginxd=/application/nginx/sbin/ngcationxnginx_config= confnginx_pid=/var/run/nginx.pidRETVAL=0prog="nginx"# Source function library../etc/rc.d/unction Source networking configuration../etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ ${NETWORKING} = "no" ] && exit 0[ ${NETWORKING} = "no" ] && exit 0[ ${NETWORKING} = "no" ] && exit 0🜎
# Start nginx daemons functions.start() {if [ -e $nginx_pid ];then $" Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo VAL }# Stop nginx daemons functions.stop() { echo -n $"Stop RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid}# reload nginx service functions.reload() { #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? . echoase. in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
exit 1esacexit $ RETVAL2.設定開機啟動服務,儲存好 /etc/init.d/nginx檔案後,執行下列指令:[root@localhost init.d]# chmod 755 /etc/init.d/nginx #文件執行權限[root@localhost init.d]# chkconfig --add nginx
[root@localhost init.d]# chkconfig --add nginx
[root@localhost init.d]# chkconfig --level 2345 nginx on 1無間斷服務重啟
[root@localhost /]# service nginx status
nginx (pid 1621 1619) 正在運作...
[ 地
[root@localhost /]# service nginx start正在啟動nginx: [root@localhost /]# service nginx reload重接 [確定]