• Nginx自启动脚本


    首先停止nginx /usr/local/nginx/sbin/nginx -s stop

    在linux系统的/etc/init.d/目录下创建nginx文件

    1、vim /etc/init.d/nginx
    在脚本中添加如下命令:
    #! /bin/bash
    # chkconfig: - 85 15
    PATH=/usr/local/nginx #nginx安装路径
    DESC="nginx daemon"
    NAME=nginx
    DAEMON=$PATH/sbin/$NAME
    CONFIGFILE=$PATH/conf/$NAME.conf
    PIDFILE=$PATH/logs/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME
    set -e
    [ -x "$DAEMON" ] || exit 0

    do_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" in
    start)
    echo -n "Starting $DESC: $NAME"
    do_start
    echo "."
    ;;
    stop)
    echo -n "Stopping $DESC: $NAME"
    do_stop
    echo "."
    ;;
    reload|graceful)
    echo -n "Reloading $DESC configuration..."
    do_reload
    echo "."
    ;;
    restart)
    echo -n "Restarting $DESC: $NAME"
    do_stop
    do_start
    echo "."
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
    exit 3
    ;;
    esac
    exit 0
    你也可以去nginx脚本地址下载使用:https://wiki.nginx.org/RedHatNginxInitScript

    修改上述两项配置项

    DAEMON 修改成nginx执行程序的路径。
    CONFIGFILE 修改成配置文件的路径。
    保存文件后设置文件执行权限

    1、chmod a+x /etc/init.d/nginx
    然后,就可以通过该脚本对nginx服务进行管理了:

    1、/etc/init.d/nginx start
    2、/etc/init.d/nginx stop
    使用chkconfig进行管理

    先将nginx服务加入chkconfig管理列表:


    1、chkconfig --add /etc/init.d/nginx
    加完这个之后,就可以使用service对nginx进行启动,重启等操作了。

    1、service nginx start
    2、service nginx stop
    设置终端模式开机启动:

    1、chkconfig nginx on
    到此nginx设置开启自启完成

  • 相关阅读:
    2020面向对象程序设计寒假作业2 题解
    题解 P3372 【【模板】线段树 1】
    Global variant VS local variant
    u2u
    深入浅出PowerShell系列
    深入浅出WF系列
    debug
    深入浅出SharePoint系列
    InfoPath debug
    深入浅出Nintex系列
  • 原文地址:https://www.cnblogs.com/liuzt/p/16427179.html
Copyright © 2020-2023  润新知