接下来聊一聊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. version.
# chkconfig: -
# 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=
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
[ -x $nginxd ] || exit
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = ] && 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
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

这样就可以了      就先这样吧

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

  1. Linux(CentOS)下设置nginx开机自动启动(2个办法)

    首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令: vim /etc/init.d/nginx 在脚本中添加如下命令: #!/bin/sh # # nginx - ...

  2. nginx设置成开机自动启动服务

    1.nginx的安装目录 /usr/local/nginx 启动nginx cd /usr/local/nginx/sbin./nginx 更改配置重启nginxcd /usr/local/nginx ...

  3. centos将nginx服务设置为开机自动启动

    centos将nginx服务设置为开机自动启动 1.在/etc/init.d下创建文件nginx 发现原来就有并且配置就是默认的,而且是正确的 命令为: vim /etc/init.d/nginx 需 ...

  4. Nginx设置成服务并开机自动启动

    在/etc/init.d下创建文件nginx [root@localhost ~]# vim /etc/init.d/nginx 其内容参考nginx官方文档 需要注意的配置: nginx=”/usr ...

  5. Window下将nginx配置为开机自动启动

    前两天看到公司window服务器上面有个nginx在跑,重启服务器后没有自动启动,需要手动运行nginx,甚是麻烦呀 上网找了一下关于将nginx配置为系统服务并且开机自动启动的解决方案,这里mark ...

  6. centos6.9下设置nginx服务开机自动启动

    首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令: vi /etc/init.d/nginx 在脚本中添加如下命令: #!/bin/sh # # nginx - ...

  7. linux开机自启动设置,自定义开机启动模版,nginx开机自启动服务

    /etc/init.d 目录,我们把shell脚本放在这个目录下来作为启动脚本 都是用来放服务脚本的,当Linux启动时,会寻找这些目录中的服务脚本,并根据脚本的run level确定不同的启动级别. ...

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

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

  9. [转] ubuntu16.04添加系统 service, 并设置开机自动启动

    转:https://www.jianshu.com/p/1958878646bd 1. 创建pfly.service文件 2.  执行 systemctl daemon-reload 3. 执行 sy ...

随机推荐

  1. 【jmeter】jmeter 压力测试

    1.添加线程组,添加CSV Data set config 设置要读取的文件的路径,内容. 指定文件名称,文件编码,变量名,分割符等. 2.添加HTTP请求,注意参数 3.添加监听信息 模拟高并发 , ...

  2. Java从控制台接受输入字符

    创建一个类,在该类的主方法中创建Scanner扫描起来封装System类的in输入流,然后提示用户输入身份证号码,并输入身份证号码的位数. 代码如下: import java.util.Scanner ...

  3. openvpn记住用户名和密码,自动连接

    1, 打开openvpn安装目录 2, 在config目录中, 找到VPN服务器的配置文件, 我的是config.ovpn,将 auth-user-pass (若已经存在)改为 auth-user-p ...

  4. lua总则

    lua官方英文文档:http://www.lua.org/manual/5.2/ lua中国开发者网址:http://bbs.luaer.cn/ <lua程序设计(第二版)>(闭合函数和闭 ...

  5. .net垃圾收集机制【转】

    在.NET Framework中,内存中的资源(即所有二进制信息的集合)分为"托管资源"和"非托管资源".托管资源必须接受.NET Framework的CLR( ...

  6. Github上star和fork比较高的vim配置方案

    https://github.com/amix/vimrchttps://github.com/humiaozuzu/dot-vimrchttps://github.com/spf13/spf13-v ...

  7. 如何在浏览器中简单模拟微信浏览器(仅限于通过User Agent进行判断的页面)

    模拟微信浏览器: .打开360极速 .F12开发者工具 .开发者模式左上方有一个手机样子的图标 点击进入 设备模式‘ .将UA选项中的字符串替换成: Mozilla/ 备注: 替换的字符串是微信浏览器 ...

  8. strcat的几种实现及性能比较

    一  原型说明 strcat()为C语言标准库函数,用于字符串拼接.函数原型声明在string.h头文件中: char *strcat(char *dest, const char *src); 该函 ...

  9. 【python3】爬取新浪的栏目分类

    目标地址: http://www.sina.com.cn/ 查看源代码,分析: 1 整个分类 在 div main-nav 里边包含 2 分组情况:1,4一组 . 2,3一组 . 5 一组 .6一组 ...

  10. Windows server 创建FTP 包括ftp的账号密码设置

    原始文章 : https://blog.csdn.net/missingshirely/article/details/50767043 最近要做个FTP上传资源的工具,以前都是我提供目录,由公司网管 ...