티스토리 뷰

HTTP 통신 기반의 Web Server. EDA(Event-Driven Architecture)로 설계되었으며 기존의 일반적인 Fork, Worker방식의 Web ServerApache보다 뛰어난 성능을 보장합니다. EDA방식에서는 각 상태(state)를 정하고 여기서 event가 발생할 때 마다 Non-blocking 으로 Process를 처리하기 떄문에 더 적은 ThreadCPU Memory 사용성이 안정적이며 쉬지않고 꾸준히 Process를 처리 할 수 있습니다


[그림 1] Nginx Architecture

요즘 apache를 대신하여 경량화된 이벤트기반의 web server로 두각을 나타내고있는 nginx라는 서버에대해 설치 해 보도록 하겠습니다.


설치환경

OS : CentOS 5.4

nginx : 1.0.15 version


Step 1. source download

http://www.nginx.org 에접속하여 현재 stable버전인 1.0.15 버전을 다운받습니다.

$ wget 'http://nginx.org/download/nginx-1.0.15.tar.gz'

$ tar xvfz nginx-1.0.15.tar.gz


Step 2. Dependency Package Install

dependency와 관련된 package들을 설치합니다.

$ yum install pcre-devel zlib-devel openssl-devel


Step 3. Source Compile

다운받은 소스파일을 컴파일합니다.

$ ./configure --sbin-path=/usr/local/nginx/sbin/nginx --with-http_ssl_module


Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/sbin"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"


$ make

$ make install


Step 4. Port Setting

/usr/local/nginx/conf/nginx.conf 파일을 열어 서버정보를 변경한다.

     35     server {
     36         listen       8080;   //http port
     37         server_name  localhost;
     38
     39         #charset koi8-r;
     40
     41         #access_log  logs/host.access.log  main;
     42
     43         location / {
     44             root   html;
     45             index  index.html index.htm;
     46         }
     47
     48         #error_page  404              /404.html;
     49
     50         # redirect server error pages to the static page /50x.html
     51         #
     52         error_page   500 502 503 504  /50x.html;
     53         location = /50x.html {
     54             root   html;
     55         }
     56
     57         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
     58         #
     59         #location ~ \.php$ {
     60         #    proxy_pass   http://127.0.0.1;
     61         #}
     62
     63         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     64         #
     65         #location ~ \.php$ {
     66         #    root           html;
     67         #    fastcgi_pass   127.0.0.1:9000;
     68         #    fastcgi_index  index.php;
     69         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
     70         #    include        fastcgi_params;
     71         #}
     72
     73         # deny access to .htaccess files, if Apache's document root
     74         # concurs with nginx's one
     75         #
     76         #location ~ /\.ht {
     77         #    deny  all;
     78         #}
     79     }


Step 5. nginx 실행

nginx가 위와같이 설치되었다면 아래의 binary 파일을 실행합니다.

$ /usr/local/sbin/nginx


Step 6. nginx server 구동 확인

http://localhost:8080 접속하여 확인한다. ( default port 80 )

$ wget 'http://localhost:8080'

$ cat index.html

$ cat index.html

<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>


step 7.  service 등록

/etc/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/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/etc/nginx/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
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    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


step 8. service 등록

chkconfig --add nginx

chkconfig --levels 235 nginx on

이상 nginx 설치에 관한 포스팅을 마치도록 하겠습니다.

다음엔 nginx server configuration에 관련하여 포스팅 하도록 하겠습니다.


by rocksea

'Developer' 카테고리의 다른 글

[ inode ] inode 관련자료  (0) 2012.04.24
[hadoop] 설치 및 clustering 셋팅  (0) 2012.04.23
SSH Local Tunneling  (0) 2012.04.18
redmine1.3.2 mylyn-connector 설치  (0) 2012.04.17
[MongoDB#1] MongoDB Installation Guide.  (2) 2012.04.13
댓글