众所周知nginx安装后需要手动去启动,每次开机之后都要执行nginx的启动命令很蛋疼。那么我们来让nginx开机启动吧

1、先創建一個nginx文件把

[root@localhost ~]# vi /etc/init.d/nginx   #这个命令可以直接创建一个nginx文件

2、把下面的代碼拷貝到剛剛創建的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: /var/run/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

注意:紅色加粗的路徑改為自己的路徑

3、給nginx文件權限

[root@localhost ~]# chmod a+x /etc/init.d/nginx

4、這一部是很重要的一步。把nginx加進開機確定的服務中

[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig --level 35 nginx on #启动nginx的级别

也可以直接把nginx的启动项加到开机执行脚本中

[root@localhost ~]# vi /etc/rc.local  #打开local文件,在后面加入代码:/etc/init.d/nginx start

好了,重启下linux试试效果吧

[root@localhost ~]# reboot  #重启linux命令

刷新浏览器是不是可以了

以后就可以通过以下命令来操作nginx
启动:service nginx start
关闭:service nginx stop
重起:service nginx restart

linux下安装nginx后开机启动篇的更多相关文章

  1. Linux下安装nginx,以及启动和停止

    1.安装 安装nginx之前,首先确保系统已经安装了依赖:g++.gcc.openssl-devel.pcre-devel和zlib-devel软件 yum install gcc-c++ yum - ...

  2. 【云服务器部署】---Linux下安装nginx

    [云服务器部署]---Linux下安装nginx 之前两篇,分别讲了:Linux下安装MySQL  和  springboot项目部署云服务器 nginx安装也是挺简单的.具体步骤如下: 第一步,下载 ...

  3. Windows 安装nginx并开机启动

    Win安装nginx并 开机启动 下载nginx安装包 nginx-1.12.2.zip,解压到D盘. https://pan.baidu.com/s/1InQa527yq35Q68c73RBb-A# ...

  4. linux下安装nginx及初步认识

    linux下安装配置nginx nginx:是一个高性能的反向代理服务器正向代理代理的是客户端,反向代理代理的是服务端. 这里以nginx-1.12.2版本为例子 1.首先去官网下载nginx-1.1 ...

  5. linux 下 安装nginx及压力测试

    linux 编译安装nginx,配置自启动脚本 下载nginx: wget http://nginx.org/download/nginx-1.8.0.tar.gz下载openssl : wget h ...

  6. Linux下安装Oracle后重启无法登录数据库ORA-01034:ORACLE not available

    Linux下安装了数据库,安装完成后可以用,今天启动就不能用了,提示Oracle not available,后来查找资料,据说是oracle服务没有打开.如下方式可以解决问题. [root@root ...

  7. 在Linux下安装nginx服务器详细教程

    首先安装centos的扩展源 yum install epel-release 安装Nginx 方法一: yum install nginx -y 查看版本号,开启nginx,查看进程 nginx – ...

  8. linux下安装nginx+php+mysql环境 详细教程

    话不多说上代码 linux环境:centos 7.0 64位 nginx:nginx-1.8.0.tar.gz php: php-7.1.1.tar.gz mysql: mysql-5.6.21.ta ...

  9. linux 下安装 nginx

    安装nginx版本为1.7.5 一.下载nginx 官方地址:http://www.nginx.org/ 下载地址:http://nginx.org/download/ Nginx官网提供了三个类型的 ...

随机推荐

  1. C# 获取sql数据库表列名,及列名说明备注信息

    获取指定表列名及备注: select * from syscolumns where id=object_id(N'表名') SELECT a.name [column], b.name type, ...

  2. FIFO深度

    async fifo的full和empty的判断: 1)binary进制,MSB相同时,LSB也相同,empty: MSB不同时,LSB相同,full 2)gray code,MSB相同时,LSB也相 ...

  3. Application.DoEvents():概念

    When you run a Windows Form, it creates the new form, which then waits for events to handle. Each ti ...

  4. iOS性能优化:Instruments

    检测内存泄露:Instruments中的Leaks 前言 如果要检测内存泄露,我们会使用Xcode7自带的Instruments中的Leaks工具来检测. 现在的开发环境是ARC,所以很少会出现内存泄 ...

  5. php strrpos()与strripos()函数不同之处在哪里呢

    strripos() 函数 定义和用法strripos() 函数查找字符串在另一个字符串中最后一次出现的位置.如果成功,则返回位置,否则返回 false.语法strrpos(string,find,s ...

  6. Tiny Rss简明安装与配置笔记

    对于某些自己喜欢的却没有RSS订阅功能的网站,可以通过Feed43定制抓取规则来获取所需信息.但由于其服务器在国外,抓取时常失败,且免费账户抓取频率太低,遂仿造他自行实现了一个并挂到服务器上,然后通过 ...

  7. jquery easyui 解析数据库返回的数据

  8. draggable datagrid columns

    $.extend($.fn.datagrid.methods,{ columnMoving: function(jq){ return jq.each(function(){ var target = ...

  9. [转]unicode,ansi,utf-8,unicode big endian的故事

    unicode,ansi,utf-8,unicode big endian的故事很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物.他们看到8个开关状态是好的 ...

  10. Hadoop集群环境搭建

    ----------------------------------------------------------- 自学记录,交流学习请发送邮件至gxz1984@gmail.com ------- ...