第一步
先运行命令关闭nginx

sudo kill `cat /usr/local/nginx/logs/nginx.pid`

第二步

vi /etc/init.d/nginx

输入以下内容

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

保存退出

第三步

chmod +x /etc/init.d/nginx

第四步

/sbin/chkconfig nginx on

检查一下

sudo /sbin/chkconfig --list nginx
nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

完成!

之后,就可以使用以下命令了

service nginx start
service nginx stop
service nginx restart
service nginx reload

/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload

Incoming search terms:

Nginx 启动脚本/重启脚本的更多相关文章

  1. nginx启动,重启,关闭命令

    nginx启动,重启,关闭命令 停止操作停止操作是通过向nginx进程发送信号(什么是信号请参阅linux文 章)来进行的步骤1:查询nginx主进程号ps -ef | grep nginx在进程列表 ...

  2. nginx 启动、重启、关闭

    一.启动 cd usr/local/nginx/sbin./nginx 二.重启 更改配置重启nginx kill -HUP 主进程号或进程号文件路径或者使用cd /usr/local/nginx/s ...

  3. nginx启动、重启、关闭

    一.启动 cd usr/local/nginx/sbin ./nginx 二.重启 更改配置重启nginx kill -HUP 主进程号或进程号文件路径 或者使用 cd /usr/local/ngin ...

  4. nginx启动,重启,关闭

    1.nginx启动: a.     /usr/path/sbin/nginx -c [/etc/path/nginx.conf] 中括号中为指定加载的配置文件,不指定则加载默认配置文件 b.     ...

  5. nginx启动或者重启失败,报错nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

    第一种方案: 1. 执行命令 :open /usr/local/etc/nginx 打开nginx安装目录 nginx安装目录默认位置有:(找到适合你的) /etc/nginx/nginx.conf, ...

  6. nginx启动、重启、重新加载配置文件和平滑升级

    Nginx有一个主进程和几个工作进程,主进程的主要作用就是读取.评估配置文件和管理工作进程,工作进程对请求做实际处理.工作进程的数量是在配置文件中配置的,一般设置为cpu的核心数*线程数. nginx ...

  7. nginx 启动、重启、关闭命令

    一.启动 cd /usr/local/nginx/sbin ./nginx 二.重启 更改配置重启nginx kill -HUP 主进程号或进程号文件路径    或者cd /usr/local/ngi ...

  8. nginx 启动/停止/重启

    启动: -c filename   : set configuration file (default: conf/nginx.conf) [root@LinuxServer sbin]# /usr/ ...

  9. nginx启动、重启、关闭、升级

    一.启动 cd usr/local/nginx/sbin ./nginx 二.重启 更改配置重启nginx kill -HUP 主进程号或进程号文件路径 或者使用 cd /usr/local/ngin ...

随机推荐

  1. 移动端Web开发之我见

    Web比App简单? 前两天有人问手机上做网页简单还是做app简单,我真答不上来.很多人会不以为意的说当然是网页简单,但真的是这样吗? 放眼现在上线的手机网页,大多数都是平时pc的技术沿用过来的,鲜有 ...

  2. Gap

    Gap Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. 获取当前的时间,转化为char[]格式unix时间戳

    /* 在这个程序当中实现获取当前的unix时间戳 转化为char[] */ #include<stdio.h> #include<stdlib.h> #include<t ...

  4. CC150 - 11.5

    Question: Given a sorted array of strings which is interspersed with empty strings, write a method t ...

  5. shell条件与循环

    一.if语句 if [expression] then elif[expression] then else fi 注 : expression前后要有空格:判断相等用 = 而不是 == : then ...

  6. 初始Python类

    一.定义类.子类.类的实例化.子类的实例化.继承.实例属性和实例方法 示例: class Fruit(): ''' 定义一个水果类,包含水果的一些属性和一些方法. ''' def __init__(s ...

  7. RN组件之ScrollView

    一.ScrollView 该组件封装了Android平台的ScrollView(滚动组件),并且提供触摸事件"responder"系统功能.使用ScrollView的时候 确保有一 ...

  8. SSH整合JBPM4.4

    第一步:导入所需jar包: 所需的jar包(使用了hibernate annotation和struts2的convention-plugin,可能有多余的包,没做清理): 第二步:修改jbpm配置文 ...

  9. 使用本函式处理后的字串会沿续到PHP程式而转入eval函数

    html码放在数据库里,通过php文件调用,经过一系列处理后,用eval函数 将希望的变量带入生成所需要的动态页.这样,我就没再看vbb源码,而转入eval函数了. 星空浪子的php中文手册是这样介绍 ...

  10. RestSharp用法小结

    今天有空,小结一下RestSharp的用法. RestSharp内置了XML和JSON的反序列化(deserializers ). application/json – JsonDeserialize ...