当前位置: 首页 > news >正文

nginx 开机自动启动

接下来聊一聊nginx的开机自启吧

看了看都是用脚本启动的,我也就不扯啥犊子了,都是前人经验

我的操作系统是centos 7 nginx版本是1.10.3

首先看一下自己的nginx配置

我的是

./configure \

--prefix=/usr/local/nginx \

--pid-path=/usr/local/nginx/logs/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--with-http_gzip_static_module \

--http-clicent-body-temp-path=/var/temp/nginx/client \

--http-proxy-temp-path=/var/temp/nginx/proxy \

--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \

--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \

--http-scgi-temp-path=/var/temp/nginx/scgi \

这些路径下面脚本文件中用的到

 

 

编写脚本 :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: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/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 /usr/local/nginx/logs/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

对于shell脚本中的部分路径请改成你主机上的nginx的相应路径

接下来更改这个脚本的访问权限:chmod a+x /etc/init.d/nginx

这样在控制台就很容易的操作nginx了:nginx {start|reload|stop|status}

如果修改了nginx的配置文件nginx.conf,也可以使用上面的命令重新加载新的配置文件并运行,可以将此命令加入到rc.local文件中,这样开机的时候nginx就默认启动了

编辑rc.local文件:vi /etc/rc.local 

加入 /etc/init.d/nginx start  保存退出

下次重启会生效

如果重启后发现并没有生效,原因是rc.local这个文件没有执行 那我们修改一下rc.local的权限

chmod +x /etc/rc.d/rc.local

这样就可以了      就先这样吧

 

转载于:https://www.cnblogs.com/guaiyouyisi/p/7799183.html

相关文章:

  • Python监控服务器利器--psutil
  • 主线程退出,子线程会退出么?
  • apue读书笔记之apue.h的设置
  • rpm 安装中的问题
  • 编程学习初体验(3. 语言的选择)
  • oracle12C—RMAN表级恢复
  • 黑客的思想
  • RPC协议
  • 命令行工具软件
  • 腾讯云ubuntu安装tensorflow
  • Python垃圾回收机制:gc模块
  • Silverlight Client←→Server数据同步备忘代码
  • Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
  • rails实现“事务”的方法
  • 威胁情报 | CCleaner后门及主流浏览器漏洞防范
  • 时间复杂度分析经典问题——最大子序列和
  • [LeetCode] Wiggle Sort
  • 《Javascript数据结构和算法》笔记-「字典和散列表」
  • HTTP中的ETag在移动客户端的应用
  • mongodb--安装和初步使用教程
  • MySQL QA
  • Spring框架之我见(三)——IOC、AOP
  • SQLServer之索引简介
  • Three.js 再探 - 写一个跳一跳极简版游戏
  • TypeScript迭代器
  • Vue官网教程学习过程中值得记录的一些事情
  • Windows Containers 大冒险: 容器网络
  • 从setTimeout-setInterval看JS线程
  • 从伪并行的 Python 多线程说起
  • 第13期 DApp 榜单 :来,吃我这波安利
  • 对JS继承的一点思考
  • 高性能JavaScript阅读简记(三)
  • 好的网址,关于.net 4.0 ,vs 2010
  • 开发基于以太坊智能合约的DApp
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 前端存储 - localStorage
  • 使用parted解决大于2T的磁盘分区
  • 双管齐下,VMware的容器新战略
  • 通过获取异步加载JS文件进度实现一个canvas环形loading图
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • ​LeetCode解法汇总307. 区域和检索 - 数组可修改
  • # 安徽锐锋科技IDMS系统简介
  • (27)4.8 习题课
  • (JS基础)String 类型
  • (附源码)springboot炼糖厂地磅全自动控制系统 毕业设计 341357
  • (九)c52学习之旅-定时器
  • (免费领源码)python#django#mysql校园校园宿舍管理系统84831-计算机毕业设计项目选题推荐
  • (三)elasticsearch 源码之启动流程分析
  • (新)网络工程师考点串讲与真题详解
  • (一)SpringBoot3---尚硅谷总结
  • (原)记一次CentOS7 磁盘空间大小异常的解决过程
  • (转)Linq学习笔记
  • ******IT公司面试题汇总+优秀技术博客汇总
  • .net core 客户端缓存、服务器端响应缓存、服务器内存缓存
  • .NET设计模式(8):适配器模式(Adapter Pattern)