Nginx 是一个很强大的高性能Web和反向代理服务器。下面介绍在linux下安装后,如何设置开机自启动。
首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:
 
vim /etc/init.d/nginx
 
在脚本中添加如下命令:
 
*********************************************************************************************************************************
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# 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: /opt/openresty/nginx/logs/nginx.pad
# config: /opt/openresty/nginx/conf/nginx.conf
nginxd=    
nginx_config=/opt/openresty/nginx/conf/nginx.conf
nginx_pid=/opt/openresty/nginx/logs/nginx.pid
RETVAL=0
prog="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" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL
 
*********************************************************************************************************************************
 
注意红色加粗部分,需要将路径改为自己机器的相应路径。
接着,设置文件的访问权限:
chmod a+x /etc/init.d/nginx                                                         (a+x参数表示 ==> all user can execute  所有用户可执行
)
 
最后将ngix加入到rc.local文件中,这样开机的时候nginx就默认启动了
vim /etc/rc.local
添加
/etc/init.d/nginx start   
保存并退出
下次重启就会生效,实现nginx的自启动。
阅读(20644)| 评论(1)
把以上脚本保存为nginx文件放入/etc/init.d/nginx
 
最后将ngix加入到rc.local文件中,这样开机的时候nginx就默认启动了
vi /etc/rc.local
添加
/etc/init.d/nginx start   
保存并退出
下次重启就会生效,实现nginx的自启动。

centos6.5_64bit-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. Linux(CentOS)系统下设置nginx开机自启动

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

  6. 设置Nginx开机自启动

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

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

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

  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 ...

  10. Centos6.5 配置Nginx开机自启动

    1.在/etc/init.d/目录下创建 nginx 文件,内容如下: #!/bin/sh # # nginx - this script starts and stops the nginx dae ...

随机推荐

  1. 2.HTTP头注入

    重新认识被人遗忘的HTTP头注入 前言 注入类漏洞经久不衰,多年保持在owasp Top 10的首位.今天就聊聊那些被人遗忘的http头注入.用简单的实际代码进行演示,让每个人更深刻的去认识该漏洞. ...

  2. nginx manager

    ====================================================@echo offrem 当前bat的作用 echo ==================beg ...

  3. Eclipse提交svn错误svn E210003 connection refused by the server

    错误明细: org.apache.subversion.javahl.ClientException: svn: E210003: connection refused by the server o ...

  4. oracle开发so easy(一)

    如何让你的程序可以在oracle数据库和sqlserver数据库自由切换? 如何让你从跨数据库开发的不适中解脱出来? 跟我来吧,我们一起开始entity framework的开发之旅.是的,entit ...

  5. 基于netty框架的轻量级RPC实现(附源码)

    前言 Rpc( Remote procedure call):是一种请求 - 响应协议.RPC由客户端启动,客户端向已知的远程服务器发送请求消息,以使用提供的参数执行指定的过程.远程服务器向客户端发送 ...

  6. 盒模型的auto值

    浮动在盒模型的auto值 属性 常规流 浮动 margin-left:auto 尽量撑满包含块 0px margin-right:auto 尽量撑满包含块 0px margin-top:auto 0p ...

  7. C#多进程并行

    为了并行执行多个任务,可以启动多个进程(并行数). 下面提供两种方法,总任务数10,最大并行数4. 一.方法1 using System; using System.Collections.Gener ...

  8. (四)从输入URL到页面加载发生了什么

    一.从输入URL到页面加载发生了什么 1.在浏览器中输入URL 如:https://www.cnblogs.com/loveapple/ URL分成协议.地址.路径三部分 协议:http.https. ...

  9. python urllib2介绍

    urllib2是Python的一个获取URLs(Uniform Resource Locators)的组件.他以urlopen函数的形式提供了一个非常简单的接口, 这是具有利用不同协议获取URLs的能 ...

  10. js new一个对象的过程,实现一个简单的new方法

    对于大部分前端开发者而言,new一个构造函数或类得到对应实例,是非常普遍的操作了.下面的例子中分别通过构造函数与class类实现了一个简单的创建实例的过程. // ES5构造函数 let Parent ...