centos6.4中如何安装nginx1.12.1

2023-04-19 06:16:00 centos6 安装 12.1

在CentOS 6.4上安装Nginx 1.12.1,可以使用以下步骤:

1. 首先,确保CentOS系统上安装了必要的编译器和库:

yum groupinstall “Development Tools”
yum install pcre-devel
yum install openssl-devel

2. 下载Nginx 1.12.1源码:

wget http://nginx.org/download/nginx-1.12.1.tar.gz

3. 解压源码:

tar -xvf nginx-1.12.1.tar.gz

4. 进入源码目录,编译安装:

cd nginx-1.12.1
./configure
make
make install

5. 添加Nginx服务:

vi /etc/init.d/nginx
#!/bin/sh
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    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
    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
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

exit $?

6. 添加Nginx到系统服务:

chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on

7. 启动Nginx服务:

service nginx start

以上就是在CentOS 6.4系统上安装Nginx 1.12.1的步骤,希望对您有所帮助。

相关文章