nginx二进制编译-启动脚本编写

首先先把这个文件上传到root目录下,并解压

 #tar zxf nginx-1.11.2.tar.gz 

写脚本

# vi nginx-running.sh

内容如下

#!/bin/bash
#chkconfig: 345 61 61          //此行的345参数表示,在哪些运行级别启动,启动序号(S61);关闭序号(K61)
#description nginx-server-scryt              //此行必写,描述服务.
nginx=/usr/local/nginx/sbin/nginx
case "$1" in
        start)
                netstat -anlpt | grep nginx
                if [ $? -eq 0 ]
                then
                        echo "nginx service running!"
                else
                        echo "nginx service not running!"
                        $nginx
                fi
        ;;
        restart)
                $nginx -s reload
                if [ $? -eq 0 ]
                then
                        echo "nginx server is begin restart"
                else
                        echo "nginx server restart"
                fi
        ;;
        stop)
                $nginx -s stop
                if [ $? -eq 0 ]
                then
                        echo "nginx server is stop"
                else
                        echo "nginx server stop,try again"
                fi
        ;;
        status)
                netstat -anlpt | grep nginx
                if [ $? -eq 0 ]
                then
                        echo "nginx server is running!"
                else
                        echo "nginx server is not running.try to restart"
        ;;
        *)
                echo "Please enter (start | restart | stop | status)"
        ;;
esac
exit 0

 安装编译环境(可省略,一般都自带编译环境)

# yum -y groupinstall "Development Tools" "Server Platform Development"

rpm安装两个rpm包

# rpm -ivh /opt/dvd/Packages/zlib-devel-1.2.7-13.el7.x86_64.rpm

# rpm -ivh /opt/dvd/Packages/pcre-devel-8.32-12.el7.x86_64.rpm 

添加一个nginx用户

# useradd -s /sbin/nologin -M nginx

# id nginx

 #cd nginx-1.11.2

# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx

#make

#make install

# cd /usr/local/nginx/sbin/

# /usr/local/nginx/sbin/nginx 

# ps aux | grep nginx

 

添加80端口

# ss -tanml | grep 80

 # cp nginx-running.sh nginx

# cp nginx /etc/init.d/

# cd /etc/init.d/

# chkconfig --add nginx

# chkconfig --list nginx

如果是关着的则用

#chkconfig nginx on

关闭防火墙打开网页

原文地址:https://www.cnblogs.com/djlsunshine/p/9713521.html