CentOS 6.5 환경 에서 LNMP 의 컴 파일 을 기반 으로 Nginx 1.8.0 stable (안정 판) 을 설치 합 니 다.

LNMP 컴 파일 링 설치 Nginx 1.8.0 stable (안정 판)
1. yum 설치 nginx 가 원 하 는 생존 환경, 즉 라 이브 러 리 파일
yum -y install make gcc gcc-c++ glibc glibc-devel automake autoconf libtool make  
2. nginx 에 시스템 사용자 추가
useradd -s /sbin/nologin -M -r nginx
3. 압축 해제 설치 nginx 1.8.0
tar xf nginx-1.8.0.tar.gz 
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx1.8 \
--sbin-path=/usr/local/nginx1.8/nginx \
--conf-path=/usr/local/nginx1.8/conf/nginx.conf \
--pid-path=/usr/local/nginx1.8/pid/nginx.pid \
--with-http_ssl_module \
--user=nginx \
--group=nginx \
--with-pcre=../pcre-8.37 \
--with-zlib=../zlib-1.2.8 \
--with-http_ssl_module \
--with-openssl=../openssl-1.0.1p 
make
make install
echo $?

4. nginx 서버 시작 프로그램 파라미터 에 대한 상세 한 설명
/usr/local/nginx-1.8.0/sbin/nginx -t
nginx 관련 매개 변수
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx-1.8.0/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
5. 설치 과정 에 나타 난 문제점
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib= option.
    :
tar xf zlib-1.2.8.tar.gz 
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib1.2.8 
make && make install
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx-1.8.0 --user=nginx --group=nginx --with-http_ssl_module --with-openssl=/usr/local/openssl/ --with-zlib=/usr/local/zlib1.2.8/

3. nginx 자동 시작 파일 설정
3.1 nginx 시스템 프로필 추가
vim /etc/sysconfig/nginx
# Configuration file for the nginx service.
NGINX=/usr/local/nginx-1.8.0/sbin/nginx
CONFFILE=/usr/local/nginx-1.8.0/conf/nginx.conf
LOCKFILE=/var/lock/subsys/nginx

3.2 nginx 서버 시작 파일 설정
vim /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx-1.8.0/conf/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/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-1.8.0/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx-1.8.0/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
   # make required directories
   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
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 >/dev/null 2>&1 || return $?
    stop
    sleep 1
    start
}
reload() {
    configtest >/dev/null 2>&1 || 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
3.3 시스템 의 nginx 서비스 설정, 검사
\ # nginx 서비스 추가.chkconfig 는 모든 런 레벨 에 시작 (S) 이나 죽 이기 (K) 입 구 를 확보 합 니 다.부족 하면 부족 한 init 스 크 립 트 에서 자동 으로 생 성 됩 니 다.
chkconfig --add nginx

\ # nginx 가 열 릴 때 실행 단계 의 상 태 를 설정 합 니 다. 기본 단 계 는 2, 3, 4, 5 입 니 다.
chkconfig nginx on

 
\ # nginx 의 시작 단 계 를 검사 합 니 다.
chkconfig --list | grep nginx
nginx          0:off1:off2:on3:on4:on5:on6:of

3.4 테스트 nginx 의 시작 서비스:
3.4.1 nginx 의 기본 설정 문법 을 테스트 합 니 다.
[root@fnw ~]# service nginx configtest
nginx: the configuration file /usr/local/nginx-1.8.0/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.8.0/conf/nginx.conf test is successful

3.4.2 nginx 서비스 시작
[root@fnw ~]# service nginx start
Starting nginx:                                            [  OK  ]

3.4.3 nginx 서비스 재 개
[root@fnw ~]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]

3.4.4, reload 부 드 러 운 재 부팅 nginx 사용
[root@fnw ~]# service nginx reload
Reloading nginx:                                           [  OK  ]

3.4.5 nginx 의 상태 보기
[root@fnw ~]# service nginx status
nginx (pid 46887 46866) is running...

3.4.6 nginx 를 닫 고 nginx 의 상 태 를 봅 니 다.
[root@fnw ~]# service nginx stop
Stopping nginx:                                            [  OK  ]
[root@fnw ~]# service nginx status
nginx is stopped
[root@fnw ~]#

이상 은 LNMP 환경 에서 nginx 의 설치 배치 과정 입 니 다. 궁금 한 점 이 있 으 면 QQ: 877306754 에 연락 하 십시오.

좋은 웹페이지 즐겨찾기