CentOS下,编译安装nginx 1.12.x

一,准备篇
1,配置网络&关闭SELINUX&配置防火墙

配置网络&关闭SELINUX&配置防火墙

2,升级软件
yum -y update
3,安装依赖
yum -y install wget gcc gcc-c++ make autoconf pcre pcre-devel openssl openssl-devel zlib zlib-devel
4,创建www用户
groupadd www && useradd -g www -s /bin/false www
二、安装篇
1,下载nginx源码
cd /usr/local/src && wget http://nginx.org/download/nginx-1.12.2.tar.gz && tar zxvf nginx-1.12.2.tar.gz && cd nginx-1.12.2
2,生成编译配置
./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module
3,编译&安装
make && make install
4,编写控制脚本
vi /etc/rc.d/init.d/nginx
#! /bin/sh
#
# chkconfig:   - 85 15 
# description:  this script starts and stops the nginx daemon

EXEC=/usr/local/nginx/sbin/nginx
CONF=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/nginx.pid

wait_for_pid () {
    try=0

    while test $try -lt 35 ; do

        case "$1" in
            'created')
            if [ -f "$2" ] ; then
                try=''
                break
            fi
            ;;

            'removed')
            if [ ! -f "$2" ] ; then
                try=''
                break
            fi
            ;;
        esac

        echo -n .
        try=`expr $try + 1`
        sleep 1

    done

}

case "$1" in
    start)
        echo -n "Starting nginx "

        $EXEC -c $CONF

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi

        wait_for_pid created $PIDFILE

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    stop)
        echo -n "Gracefully shutting down nginx "

        if [ ! -r $PIDFILE ] ; then
            echo "warning, no pid file found - nginx is not running ?"
            exit 1
        fi

        $EXEC -s quit

        wait_for_pid removed $PIDFILE

        if [ -n "$try" ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
    ;;

    status)
        if [ ! -r $PIDFILE ] ; then
            echo "nginx is stopped"
            exit 0
        fi

        PID=`cat $PIDFILE`
        if ps -p $PID | grep -q $PID; then
            echo "nginx (pid $PID) is running..."
        else
            echo "nginx dead but pid file exists"
        fi
    ;;

    force-quit)
        echo -n "Terminating nginx "

        if [ ! -r $PIDFILE ] ; then
            echo "warning, no pid file found - nginx is not running ?"
            exit 1
        fi

        $EXEC -s stop

        wait_for_pid removed $PIDFILE

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    restart)
        $0 stop
        $0 start
    ;;

    reload)

        echo -n "Reloading nginx"

        if [ ! -r $PIDFILE ] ; then
            echo "warning, no pid file found - nginx is not running ?"
            exit 1
        fi

        $EXEC -s reload

        echo " done"
    ;;

    configtest)
        $EXEC -t -c $CONF
    ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
        exit 1
    ;;

esac
chmod +x /etc/rc.d/init.d/nginx && chkconfig  nginx on
service nginx start
service nginx stop
service nginx force-quit
service nginx restart
service nginx reload
service nginx configtest
三、优化篇

暂无

你可能感兴趣的:(CentOS下,编译安装nginx 1.12.x)