Linux下源码安装并配置Nginx(2)

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
# END

用/root/service-nginx.sh替换/etc/init.d/nginx

mv /root/service-nginx.sh /etc/init.d/nginx

赋予可执行限权

chmod 755 /etc/init.d/nginx

执行

systemctl start nginx

源码方式安装nginx,自动化安装脚本

#!/bin/bash

# installation configuration
NGINX_VERSION=1.12.2
NGINX_SRC_PATH=/root
NGINX_BIN_PATH=/usr/local/nginx

# disable firewall
systemctl stop firewalld
setenforce 0

# installation dependence
yum install -y pcre-devel zlib-devel openssl-devel wget gcc

# download nginx source package
cd ${NGINX_SRC_PATH}
wget ${NGINX_VERSION}.tar.gz

# unzip source package
tar -xzvf nginx-${NGINX_VERSION}.tar.gz
cd ./nginx-${NGINX_VERSION}

# install nginx
./configure --prefix=${NGINX_BIN_PATH} --with-http_ssl_module
make & make install

# start nginx service
cd ${NGINX_BIN_PATH}/sbin
./nginx

# END

Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/669756f48ae4f9b8a5b4086de7383bf2.html