Nginx 설치

  • 본 문서에서는 Nginx 컴파일에 대해서 다루어 본다.

Nginx란?

Nginx란 아파치와 같은 웹 서버 소프트웨어로 웹 서버의 기능만이 아니라 Reverse Proxy, Mail Proxy 기능도 가진다. 자세한 내용은 http://ko.wikipedia.org/wiki/Nginx 를 참고 합니다.

  • 설치환경 OS : CentOS-6.4 x86_64
  • 소스코드 다운로드 http://nginx.org/en/download.html 에서 최신 소스를 다운 받는다.
    > 본 문서에서는 현재 Stable 버전인 nginx-1.4.4 버전으로 설치를 진행하겠다.
  • 설치 다운받은 파일을 적당한 위치에 압축을 해제한다. > 본 문서에서는 /usr/local/src 에 압축을 해제하고 진행한다.
  • 설치에 필요한 패키지 설치
# yum -y install gcc gcc-c++ make autoconf wget libxml2-devel perl perl-devel pcre-devel openssl-devel zlib cpan
  • 컴파일
# ./configure
--prefix=/usr/local/nginx
--with-pcre
--with-http_mp4_module
--with-http_stub_status_module
--with-http_ssl_module
# make
# make install
  • nginx 서비스 등록 /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:      /etc/nginx/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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/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' -`
   if [ -z "`grep $user /etc/passwd`" ]; then
       useradd -M -s /bin/nologin $user
   fi
   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
}
  • 서비스 등록
# chmod o+x /etc/rc.d/init.d/nginx
# chkconfig --add nginx
  • nginx 구동
# service nginx start
  • nginx 설치 확인 제대로 설치 했는지 웹 브라우저에서 확인한다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다