1. 简介
nginx源码安装完成后默认不会注册为系统服务,所以需要手工添加系统服务脚本。在/etc/init.d目录下新建nginx文件,并更改权限其即可。
2. 新建nginx文件
vim /etc/init.d/nginx
填写一下内容(根据自己的实际目录修改):
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by caffreyxin at 2007.10.15.
# it is v.0.0.1 version.
# if you find any errors on this scripts, please contact caffreyxin.
# and send mail to xinyflove at sina dot com.
#
# 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=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0prog="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
}
# 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 "$1" instart)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1esac
exit $RETVAL
根据自己实际安装目录,修改这两行:
nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf
3. 修改文件权限
chmod 755 /etc/init.d/nginx
4. 设置开机启动
chkconfig nginx on
5.查看开机启动的服务
chkconfig --list
附:
启动服务:service nginx start 停止服务:service nginx stop 重启服务:service nginx reload
温馨提示:
linux设置开启启动项参考琼杰笔记文档:1. Linux开机启动项的查看和设置方法总结 2. Centos7设置服务开机自启动方法
您暂时无权查看此隐藏内容!
内容查看价格0.1元立即支付
					注意:本站少数资源收集于网络,如涉及版权等问题请及时与站长联系,我们会在第一时间内与您协商解决。如非特殊说明,本站所有资源解压密码均为:zhangqiongjie.com。
作者:1923002089
琼杰笔记






		
评论前必须登录!
注册