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



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

相关文章
|
22天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
24 0
|
21天前
|
前端开发 应用服务中间件 nginx
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
83 0
|
1天前
|
安全 应用服务中间件 网络安全
SSL原理、生成SSL密钥对、Nginx配置SSL
现在,你的Nginx虚拟主机应该已经配置了SSL,可以通过HTTPS安全访问。确保在生产环境中使用有效的SSL证书来保护通信的安全性。
6 0
|
3天前
|
域名解析 缓存 负载均衡
Nginx正向代理域名的配置
Nginx正向代理域名的配置
|
4天前
|
前端开发 JavaScript 应用服务中间件
修改Jeecg-boot context-path(附加图片+Nginx配置)
修改Jeecg-boot context-path(附加图片+Nginx配置)
12 0
|
5天前
|
应用服务中间件 nginx
yum 安装报错 No package nginx available Error:Nothing to do
yum 安装报错 No package nginx available Error:Nothing to do
12 1
|
14天前
|
应用服务中间件 nginx
nginx进行反向代理的配置
在Nginx中设置反向代理的步骤:编辑`/etc/nginx/nginx.conf`,在http段加入配置,创建一个监听80端口、服务器名为example.com的虚拟主机。通过`location /`将请求代理到本地3000端口,并设置代理头。保存配置后,使用`sudo nginx -s reload`重载服务。完成配置,通过example.com访问代理服务器。
22 0
|
16天前
|
应用服务中间件 网络安全 nginx
nginx配置https访问
nginx配置https访问
26 0
|
24天前
|
应用服务中间件 nginx
nginx配置访问qicaitun.com强制跳转www.qicaitun.com
nginx配置访问qicaitun.com强制跳转www.qicaitun.com
9 0
|
25天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
22 0