135-1821-9792

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

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

目前创新互联公司已为近1000家的企业提供了网站建设、域名、网站空间网站托管、企业网站设计、金台网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

实验环境: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服务器并配置启动脚本这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


文章名称:怎么Nginx服务器并配置启动脚本
转载来于:http://kswsj.com/article/jsesdj.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号