#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place
in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate
command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'

### BEGIN INIT INFO
#
Provides:         
nginx
#
Required-Start:   
$all
#
Required-Stop:    
$all
#
Default-Start:    
2 3 4 5
#
Default-Stop:     
0 1 6
# Short-Description: starts the nginx web server
#
Description:      
starts nginx using start-stop-daemon
### END INIT INFO

# Author:   licess
# website:  http://lnmp.org

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

NAME=nginx
NGINX_BIN=/data/apps/nginx/sbin/$NAME

CONFIGFILE=/data/apps/nginx/conf/$NAME.conf
PIDFILE=/data/logs/nginx/$NAME.pid

case "$1" in
    start)
       
echo -n "Starting $NAME... "

if netstat -tnpl | grep -q nginx;then
           
echo "$NAME (pid `pidof $NAME`) already running."
           
exit 1
       
fi

$NGINX_BIN -c $CONFIGFILE

if [ "$?" != 0 ] ; then
           
echo " failed"
           
exit 1
       
else
           
echo " done"
       
fi
       
;;

stop)
       
echo -n "Stoping $NAME... "

if ! netstat -tnpl | grep -q nginx; then
           
echo "$NAME is not running."
           
exit 1
       
fi

$NGINX_BIN -s stop

if [ "$?" != 0 ] ; then
           
echo " failed. Use force-quit"
           
exit 1
       
else
           
echo " done"
       
fi
       
;;

status)
       
if netstat -tnpl | grep -q nginx; then
           
PID=`pidof nginx`
           
echo "$NAME (pid $PID) is running..."
       
else
           
echo "$NAME is stopped"
           
exit 0
       
fi
       
;;

force-quit)
       
echo -n "Terminating $NAME... "

if ! netstat -tnpl | grep -q nginx; then
           
echo "$NAME is not running."
           
exit 1
       
fi

kill `pidof $NAME`

if [ "$?" != 0 ] ; then
           
echo " failed"
           
exit 1
       
else
           
echo " done"
       
fi
       
;;

restart)
       
$0 stop
       
sleep 1
       
$0 start
       
;;

reload)
       
echo -n "Reload service $NAME... "

if netstat -tnpl | grep -q nginx; then
           
$NGINX_BIN -s reload
           
echo " done"
       
else
           
echo "$NAME is not running, can't reload."
           
exit 1
       
fi
       
;;

configtest)
       
echo -n "Test $NAME configure files... "

$NGINX_BIN -t
       
;;

*)
       
echo "Usage: $0
{start|stop|force-quit|restart|reload|status|configtest}"
       
exit 1
       
;;

esac

# chmod +x /etc/init.d/nginx
# sysv-rc-conf

退出按【q】 就行了
上次忘记说了,这次补一下  这个【1\2\3\4\5\0\6\S】启动选项最后有个【 S
】的选项,他的意思表示开机后就会运行的服务。
运行级别说明:
S   表示开机后就会运行的服务
0   表示关机
1   表示单用户模式 
(类似windows的安全模式)
2   表示无网络服务的多用户模式
3   表示多用户模式
4   系统预留(暂没使用)
5   表示多用户图形模式
6   表示重启
打X 表示开启该服务。
 
  1. sysv-rc-conf nginx on
  2.  
  3. service nginx -s reload | stop | restart | start

Ubuntu Nginx 开机自启动的更多相关文章

  1. centos7.x设置nginx开机自启动

    设置nginx开机自启动(centos7.x) 第一步:进入到/lib/systemd/system/目录 [root@iz2z init.d]# cd /lib/systemd/system/ 第二 ...

  2. Centos下安装并设置nginx开机自启动

    一.在centos环境下安装下载并安装nginx,由于nginx需要依赖一些环境才能安装,主要依赖g++.gcc.openssl-devel.pcre-devel和zlib-devel这些环境,首先得 ...

  3. 设置Apache(httpd)和Nginx 开机自启动

     方法1: 进入目录: vi  /etc/rc.d/rc.local #设置apache 和 nginx 开机自启动/usr/sbin/apachectl start/usr/sbin/nginx s ...

  4. centos7下安装、配置Nginx、设置Nginx开机自启动

    测试环境: [root@centos-linux ~]# cat /etc/redhat-releaseCentOS Linux release 7.6.1810 (Core) [root@cento ...

  5. Ubuntu14.04配置nginx开机自启动项

    原文: https://www.jianshu.com/p/2e03255cfabb ubuntu配置开机自动启动服务 ---------------------------------------- ...

  6. Linux(CentOS)系统下设置nginx开机自启动

    Nginx 是一个很强大的高性能Web和反向代理服务器.下面介绍在linux下安装后,如何设置开机自启动.首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:vi ...

  7. 设置Nginx开机自启动

    Nginx 是一个很强大的高性能Web和反向代理服务器.虽然使用命令行可以对nginx进行各种操作,比如启动等,但是还是根据不太方便.下面介绍在linux下安装后,如何设置开机自启动. 首先,在lin ...

  8. Centos8配置Nginx开机自启动

    第一步:创建service文件,并编辑(可理解为开机时自动启动Nginx的脚本服务文件) vim /lib/systemd/system/nginx.service /lib 与 /usr/lib 里 ...

  9. 十一、设置Nginx开机自启动

    一.创建nginx.service文件 [root@svr7 ~]# vim /lib/systemd/system/nginx.service [Unit]Description=nginx ser ...

随机推荐

  1. 一个简单的迷你jQuery实现

    //仅提供与学习使用(function () { var _$ = window.$; var _jQuery = window.jQuery; //暴露外部使用的一个接口 var jQuery = ...

  2. 高频dom操作和页面性能优化(转载)

    作者:gxt19940130 原文:https://feclub.cn/post/content/dom 一.DOM操作影响页面性能的核心问题 通过js操作DOM的代价很高,影响页面性能的主要问题有如 ...

  3. [搜索]ElasticSearch Java Api(一) -添加数据创建索引

    转载:http://blog.csdn.net/napoay/article/details/51707023 ElasticSearch JAVA API官网文档:https://www.elast ...

  4. Python之可变类型与不可变类型

    Python常见的数据类型有:数字 字符串 元组 列表 字典 不可变类型:数字 字符串 元组 可变类型: 列表 字典 a = 100 b = [100] def num1(x): x += x pri ...

  5. Asp.net Core中SignalR Core预览版的一些新特性前瞻,附源码(消息订阅与发送二进制数据)

    目录 SignalR系列目录(注意,是ASP.NET的目录.不是Core的) 前言 一晃一个月又过去了,上个月有个比较大的项目要验收上线.所以忙的脚不沾地.现在终于可以忙里偷闲,写一篇关于Signal ...

  6. JAVA8新特性(一)

    default拓展方法 java8为接口声明添加非抽象方法的实现,也成为拓展方法. public interface Formula { void doSomething(); default voi ...

  7. SPOJ SERGRID - Grid BFS

    SERGRID - Grid no tags  You are on an nxm grid where each square on the grid has a digit on it. From ...

  8. oracle触发器 调用 web接口

    最近要求开发当数据表发生变化的时候调用web接口的需求,上网找了好几篇文章看着都觉得不是很好,也根据别人的思路去实现了下,感觉都不太理想,最后使用URLConnection实现了调用.具体查看一下代码 ...

  9. nginx防恶意域名解析

    今天无意间查看访问日志发现一个fhxywh.com的域名居然解析到了我的服务器,也就是说通过这个域名也能访问我的博客,这个就是赤裸裸的恶意域名解析了. 这个危害非常大,不仅会影响用户,而且不利于SEO ...

  10. 11g使用非duplicate方式创建物理standby要注意的问题总结

    在上篇博文中,使用了duplicate方式来创建物理standby http://blog.csdn.net/aaron8219/article/details/38434579 今天来说说在11g中 ...