티스토리 뷰

2015년 9월 17일자 최신 버전 사용
다운로드
설치를 위해서는 우선 소스를 다운로드 받아야 한다. 아래 URL을 통해서 다운로드 받을 수 있다. 필자는 안정버전을 다운로드 받을 것이다. 필자는 1.8.0 버전을 사용할 것이다.

압축풀기
다운로드 받은 파일의 압축을 해제하자. 
1
2
3
4
tar -xvzf nginx-1.8.0.tar.gz
mv nginx-1.8.0 nginx
cd nginx
./configure --prefix=/usr/local/nginx --user=www-data --group=www-data

에러 발생
에러 화면
1
2
3
4
 ./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
에러 - PCRE라이브러리 설치를 해라라고 쓰여 있음 안쓸꺼면 without으로 제거 해라라고 됨



의존성 확인
아래의 의존성 패키지들은 apt-get, yum과 같은 패키지 관리자를 이용해서 설치하는 것이 편리하다. 이번 수업에서는 일부러 직접 컴파일 하는 법을 다루고 있다.
1
2
3
PCRE
openssl
zlib

PCRE

NGINX는 Perl5에서 사용하는 정규표현식 라이브러리인 PCRE를 사용한다. 아래의 주소에서 다운로드 한다. 필자는 소스 다운로드 페이지를 경유해서 아래의 주소에서 가장 최신 버전의 파일을 다운 받았다. 

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

아래와 같이 압축을 푼다. 

1
tar xvf pcre-8.37.tar.gz
mv

openssl

https 모듈인 HttpSslModule을 사용하기 위해서는 openssl이 필요하다. openssl은 아래의 위치에서 다운로드 할 수 있다. 필자는 최신버전을 다운로드 받았다. 

http://www.openssl.org/source/

압축을 해제한다.

1
2
tar -xzvf openssl-fips-2.0.10.tar.gz;
mv openssl-fips-2.0.10 openssl

zlib

ngx_http_gzip_module 모듈을 사용하기 위해서는 zlib 라이브러리가 있어야 한다. zlilb의 홈페이지를 방문해서 잘 찾아보면 zlib의 소스코드를 다운로드 받을 수 있는 섹션이 있다. zlib의 홈페이지는 아래와 같다.

http://zlib.net/

파일을 다운로드 받는다. 

압축을 해제한다.

1
2
unzip zlib128.zip
mv zlib-1.2.8 zlib

unzip은 apt-get install unzip과 같은 명령으로 설치 할 수 있다.


사용자 추가

 웹서버의 워커 유저는 www-data를 사용한다. www-data를 만드는 법은 아래와 같다. 
1
useradd --shell /sbin/nologin www-data
--shell는 로그인 할 수 없는 유저라는 뜻이다. 즉 NGINX를 실행할 때만 사용될 뿐 허가되지 않은 일을 하지 못하는 유저라는 의미가 된다. 

컴파일러

C, C++ 컴파일러 사용
1
yum install gcc-c++ -y;


Init에 등록 하기

 /etc/init.d/
# vi /etc/init.d/nginx
--shell는 로그인 할 수 없는 유저라는 뜻이다. 즉 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/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid
# user:        nginx

# 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.lock

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
            ;;
   *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
권한 변경 후 실행 명령어
1
2
chmod +x /etc/init.d/nginx
systemctl start nginx




'NginX' 카테고리의 다른 글

centos 7 + nginx + php + mariadb + phpmyadmin install  (0) 2015.08.25
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함