安装配置略,开机启动脚本如下:
建立脚本文件,/etc/init.d/ngx_start, ngx_start文件内容如下
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
nginxd=/usr/local/nginx/sbin/nginx #这里注意,改成你自己的安装nginx目录下的启动文件,
nginx_config=/usr/local/nginx/conf/nginx.conf #这里也是,你自己的安装的配置文件
nginx_pid=/usr/local/nginx/logs/nginx.pid #这里也是一样的
RETVAL=0
. /etc/rc.d/init.d/functions
#/etc/sysconfig/network
#[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
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
# nginx Startup script for the Nginx HTTP Server
nginxd=/usr/local/nginx/sbin/nginx #这里注意,改成你自己的安装nginx目录下的启动文件,
nginx_config=/usr/local/nginx/conf/nginx.conf #这里也是,你自己的安装的配置文件
nginx_pid=/usr/local/nginx/logs/nginx.pid #这里也是一样的
RETVAL=0
. /etc/rc.d/init.d/functions
#/etc/sysconfig/network
#[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
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() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx
/usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
$nginxd -s reload
#RETVAL=$?
#echo
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx
/usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
$nginxd -s reload
#RETVAL=$?
#echo
}
case "$1" 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
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
并给权限: chmod +x /etc/init.d/ngx_start
再打开/etc/rc.local加入如下,这样nginx就默认开机启动了
/etc/init.d/ngx_start start
如有不明白的地方,可以加群讨论(284215611)