1. 설치 환경

 - CentOS 6.4



2. 다운로드

 - http://nginx.org/download/   

(2014. 3. 28 현재 1.4.7 (Stable) / 1.5.12 (Mainline)이 최신 버전임)

 - 여기서는 1.4.7을 설치한다.


# cd /usr/local/src

# wget http://nginx.org/download/nginx-1.4.7.tar.gz



3. 압축을 풀어서 넣는다.


# tar -xvzf nginx-1.4.7.tar.gz



4. 컴파일 설정 및 설치


# cd nginx-1.4.7

# ./configure --prefix=/usr/local/nginx-1.4.7 --user=daemon --group=developer --with-http_realip_module --with-http_stub_status_module

# make

# make install


* configure 옵션은 참고문서 3번을 참고



5. 설정


# cd /usr/local/nginx-1.4.7/conf

# vi nginx.conf


* 환경 설정은 참고문서 4번을 참고



6. 시스템 방화벽 오픈 (기본 포트인 80일 경우)


# lokkit -p 80:tcp



7. (옵션) 설치 위치 심볼릭 링크 생성


# cd /usr/local

# ln -s ./nginx-1.4.7 nginx


* 운용시 가동중인 웹 서버 위치로 바로 이동할 수 있도록 심볼릭 링크 생성




8. 실행스크립트 등록


# cd /etc/init.d

# vi /etc/init.d/nginx



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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# 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:     /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"
 
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
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac



# chmod +x /etc/init.d/nginx



9. 설정파일 검사 및 실행


# ngix configtest    // 검사

# nginx start        // 웹 서버 구동




10. 확인


웹 브라우저에서 웹페이지가 뜨는지 확인



11. 로그 분할 설정


1) logroteate 설치 확인


# yum list | grep logrotate


2) 설정 파일 작성


# cd /etc/logrotate.d


# vi ./nginx


1
2
3
4
5
6
7
8
9
10
11
12
13
/usr/local/nginx/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 nginx adm
sharedscripts
postrotate
[ -f /usr/local/nginx/logs/nginx.pid ] && kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
endscript
}



3) 테스트


# logrotate -d /etc/logrotate.conf











* 참고 자료


1. NGINX 사이트 : http://nginx.org


2. NGINX 설치기 : http://blog.beany.co.kr/archives/2422


3. 컴파일 옵션 : http://webdir.tistory.com/238


4. 환경 설정

 - http://ohgyun.com/479

 - http://ohgyun.com/480

 - http://ohgyun.com/481


5. 로그 분할 설정 : http://blog.galgulee.com/nginx-log-rotate-시키기-logrotate-사용/


Posted by 카프러브