nginx开机启动

2019-03-06 23:46|来源: 网路

添加脚本文件

vim /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:      /etc/nginx/nginx.conf

# pidfile:     /var/run/nginx/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/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

lockfile=/var/lock/nginx.lock

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

保存退出


[root@master nginx]# chmod +x/etc/init.d/nginx

[root@master nginx]# chkconfig nginx on

[root@master nginx]# chkconfig --list nginx

nginx             0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭


至此就可以使用系统命令了

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


相关问答

更多
  • 无奈鄙厂没有mac,因各种网络限制,加域等,无法使用Linux作为工作OS。故为了能继续下去,还是接受了从OS X到windows的迁移,至今已有半年有余,总的说来其实也还行   *inux 下,Nginx的开机启动很简单,突然切到windows下有些不知所措。   于是在网上各种搜索,用了一种靠谱的办法就是下载一个win wrap的程序,然后配置xml,执行install命令。但是上诉方法也过于冗余,麻烦。   介绍下比较简单的办法:   1、windows下Nginx目录,nginx.exe 右键生成一 ...
  • 路径启动,默认在/usr/local/nginx/sbin/nginx 启动:/usr/local/nginx/sbin/nginx 平滑重启:/usr/local/nginx/sbin/nginx -s reload 停止:/usr/local/nginx/sbin/nginx -s stop 重启:/usr/local/nginx/sbin/nginx -s restart
  • 点击电脑的 开始—运行—msconfig—查看启动项 关闭nginx不就可以了 呵呵
  • 这个进程不是nginx的运行进程,而是你grep搜索的时候生成的,不需要kill; 如果后台有nginx进程,grep之后,不会只有这1条进程结果的。 # ps -ef | grep --color=auto nginx nobody 8554 30650 0 Mar03 ? 00:00:00 nginx: worker process root 20969 20930 0 18:13 pts/2 00:00:00 grep --color=auto nginx root 30650 1 0 2014 ? ...
  • 设置文件的访问权限 chmod a+x /etc/init.d/nginx (a+x ==> all user can execute 所有用户可执行) 这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx 同样的修改了nginx的配置文件nginx.conf,也可以使用上面的命令重新加载新的配置文件并运行,可以将此命令加入到rc.local文件中,这样开机的时候nginx就默认启动了 vi /etc/rc.local 加入一行 /etc/init. ...
  • 打开【360安全卫士】,点击【木马查杀】 选择【自定义扫描】 然后把你出现问题的U盘打上勾,接着点击【开始扫描】 稍等片刻。。。 你会发现现在扫描出一些木马,那些就是把u盘文件变成快捷方式的罪魁祸首,点击【立即处理】,把这些木马清理掉 5 再次打开你的U盘,你的那些文件已经不再是快捷方式了
  • 路径启动,默认在/usr/local/nginx/sbin/nginx 启动:/usr/local/nginx/sbin/nginx 平滑重启:/usr/local/nginx/sbin/nginx -s reload 停止:/usr/local/nginx/sbin/nginx -s stop 重启:/usr/local/nginx/sbin/nginx -s restart
  • nginx是源码安装的吗?你的系统是什么centos6还是7 复制下面代码自己修改确定nginx安装位置,到/etc/init.d/nginx #!/bin/bash # chkconfig: - 99 98 #description: nginx is a World Wide Web server. It is used to serve nginx="/usr/local/nginx/sbin/nginx" nginxpid="/usr/local/nginx/nginx.pid" php="/usr ...
  • 开机启动脚本[2019-10-24]

    一、最简单的方法就是放到启动项了。 可以在开始菜单的 启动 文件夹里创建一个快捷方式 开始——程序——启动(右键打开)——粘贴即可 二、添加到任务计划里即可 开始——控制面板——任务计划——添加任务计划——任务计划向导——下一步(找到你要添加的程序,没有的话自己浏览路径添加即可)——下一步——输入计划名称 选择【计算机启动时执行】——下一步【输入管理员密码即可】——完成 注:当然也可以设置在那个时段执行、关闭。 三、添加到注册表里(摘的) 添加一个启动程序(如果这个程序不是自启动的),首先要在注册表内注入信 ...
  • 如果是应用软件,比如QQ,超级旋风什么的,可以在软件上设置的,或者删除重新装一下. 系统软件的话,在开始菜单里,点运行,输入MISCONFIG,就有启动项的