Nginx服务安装与启动脚本配置

简介:

实验环境:RHEL7.2 x64-176,IP地址:192.168.1.176
实验工具:wKiom1eIIiyy4xGGAAANt1ehlE0333.jpg-wh_50

实验步骤:

1、安装nginx服务器
2、配置nginx启动脚本
3、文件设置并验证结果

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1、安装nginx服务器

[root@localhost~]# useradd nginx -s /sbin/nologin -M   #创建 nginx用户

[root@localhost~]# id nginx       #验证

uid=1001(nginx)gid=1001(nginx) 组=1001(nginx)
[root@localhost ~]# yum install pcre pcre-devel openssl openssl-devel -y   #安装依赖相关包
[root@localhost ~]# tar xf nginx-1.9.14.tar.gz  #解压nginx源码包到当前目录
[root@localhost ~]# cd nginx-1.9.14/    #进入解压后的nginx目录
[root@localhost nginx-1.9.14]# ./configure --user=nginx --group=nginx  #配置nginx

[root@localhostnginx-1.9.14]#make && make install #编译安装nginx

[root@localhostnginx-1.9.14]# /usr/local/nginx/sbin/nginx -t  #检查语法

[root@localhostnginx-1.9.14]# /usr/local/nginx/sbin/nginx #启动nginx

#访问虚拟机IP地址测试出现 nignx 成功
wKiom1eIImXSOFkUAABoxFaO-3k129.png-wh_50

2、配置nginx启动脚本
[root@localhost~]# vim nginx

==============================================================
#! /bin/bash

# chkconfig:2345 99 20

#description:nginx-server

nginx=/usr/local/nginx/sbin/nginx

case $1 in

 

    start)

        netstat -anlpt | grep nginx

        if [ $? -eq 0 ]

            then

                echo "nginx-server isalready running"

            else

                echo "nginx-server beginstart"

                   $nginx

         fi

    ;;

    stop)

        $nginx -s stop

        if [ $? -eq 0 ]

            then

                echo "nginx-server isstoped"

            else

                echo "nginx-server stopfail,try again"

        fi

        ;;

    status)

        netstat -anlpt | grep nginx

        if [ $? -eq 0 ]

            then

                echo "nginx-server isrunning"

            else

                echo "nginx-server isstoped"

            fi

        ;;

    restart)

        $nginx -s reload &>/dev/null

        if [ $? -eq 0 ]

            then

                echo "nginx-server isbegin restart"

            else

                echo "nginx-server restartfail"

        fi

        ;;

    *)

                echo "please enter {startrestart status stop}"

        ;;

esac

exit 0 
================================================================

3、文件设置并验证结果

[root@localhost~]# cp nginx /etc/init.d/  #将启动文件复制到/etc/init.d目录下
[root@localhost ~]# chmod +x /etc/init.d/nginx  #设置可执行权限
[root@localhost ~]# chkconfig --add nginx #将nginx添加为系统的服务
[root@localhost ~]# chkconfig --list nginx #查看nginx的开机运行级别

wKioL1eIIlOgJN0QAABJbr3l2so047.png-wh_50

本文转自xinsz08の平行时空博客51CTO博客,原文链接http://blog.51cto.com/xinsz08/1826562如需转载请自行联系原作者


维度2018

相关文章
|
9月前
|
缓存 应用服务中间件 nginx
【Nginx二】——Nginx常用命令 配置文件
【Nginx二】——Nginx常用命令 配置文件
71 0
|
9月前
|
应用服务中间件 nginx Docker
Nginx中常用命令与Nginx.conf配置文件详解
Nginx中常用命令与Nginx.conf配置文件详解
78 2
Nginx中常用命令与Nginx.conf配置文件详解
|
监控 应用服务中间件 nginx
Nginx的安装到配置(上)
本系列你将了解到 1,nginx的简单安装 2,nginx的访问配置 3,使用nginx搭建一个简单文件服务器 4,使用nginx搭建一个简单的实时日志监控页面
Nginx的安装到配置(上)
|
监控 应用服务中间件 nginx
Nginx的安装到配置(下)
我们继续接着上篇来介绍
Nginx的安装到配置(下)
|
缓存 应用服务中间件 nginx
|
应用服务中间件 开发工具 nginx
nginx的安装和配置
仅供参考, 不同系统操作可能会不一样, 中间遇到错误, 找一下错误原因, 一般是单词”error“后的一句, 复制, 百度, vim操作下面有注释 首先是域名解析到指定的服务器 安装nginx 方法一:这个是最简单的方法,但是很有可能会失败,这里搞定了就能直接去配置nginx了 1.
|
Web App开发 应用服务中间件 Linux
|
应用服务中间件 数据安全/隐私保护 nginx
Nginx 的安装与配置.
一、下载 Linux:CentOS 7.3 64位 Nginx:nginx-1.13.1 安装目录:/usr/local/ wget http://nginx.org/download/nginx-1.
1175 0
|
Web App开发 应用服务中间件 PHP