一、建立服務指令碼
vim /etc/init.d/nginx
指令碼內容如下
#! /bin/sh# chkconfig: - 85 15PATH=/web/server/nginx/sbinDESC="nginx daemon"NAME=nginxDAEMON=/web/server/nginx/sbin/$NAMECONFIGFILE=/web/server/nginx/conf/$NAME.confPIDFILE=/web/server/nginx/logs/$NAME.pidSCRIPTNAME=/etc/init.d/$NAMEset-e[ -x "$DAEMON" ] || exit0do_start() {$DAEMON -c $CONFIGFILE || echo -n "nginx already running"}do_stop() {$DAEMON-s stop || echo -n "nginx not running"}do_reload() {$DAEMON-s reload || echo -n "nginx can't reload"}case"$1"instart)echo -n "Starting $DESC: $NAME"do_startecho".";;stop)echo -n "Stopping $DESC: $NAME"do_stopecho".";;reload|graceful)echo -n "Reloading $DESC configuration..."do_reloadecho".";;restart)echo -n "Restarting $DESC: $NAME"do_stopdo_startecho".";;*)echo"Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2exit3;;esacexit0
二、添加服務
chkconfig--addnginx
三、測試
service nginx start
service nginx stop
service nginx restart
service nginx reload
以上就介紹了Nginx系列(三.nginx註冊為linux系統服務),包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。