怎么Nginx服务器并配置启动脚本

发布时间:2021-08-27 14:39:02 作者:chen
来源:亿速云 阅读:233

这篇文章主要讲解了“怎么Nginx服务器并配置启动脚本”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么Nginx服务器并配置启动脚本”吧!

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

实验步骤:

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 成功

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的开机运行级别

感谢各位的阅读,以上就是“怎么Nginx服务器并配置启动脚本”的内容了,经过本文的学习后,相信大家对怎么Nginx服务器并配置启动脚本这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. Nginx服务器的搭建及配置
  2. Nginx服务器如何配置HTTPS

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nginx

上一篇:Linux系统下Git的基本配置和使用方式

下一篇:Django缓存系统的用法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》