nginx 간단 설치

1. Nginx 다운로드 및 설치
  
  다운로드 사이트 : http://nginx.org/en/download.html



[root@localhost ~]# wget http://nginx.org/download/nginx-0.8.37.tar.gz


[root@localhost ~]# tar xvfz nginx-0.8.37.tar.gz


[root@localhost ~]# cd nginx-0.8.37


설치에 앞서 관련 모듈을 설치한다


[root@localhost nginx-0.8.37]# yum -y install gcc pcre-devel bzip2-devel openssl-dev


[root@localhost nginx-0.8.37]# yum -y install GeoIP GeoIP-devel GeoIP-data perl-Geo-IP


[root@localhost nginx-0.8.37]# ./configure –prefix=/usr/local/nginx \
–conf-path=/usr/local/nginx/conf/nginx.conf \
–sbin-path=/usr/local/nginx/sbin/nginx \
–pid-path=/usr/local/nginx/log/nginx.pid \
–lock-path=/usr/local/nginx/log/nginx.lock \
–error-log-path=/usr/local/nginx/log/error.log \
–user=nobody –group=nobody \
–with-http_ssl_module \
–with-http_realip_module \
–with-http_addition_module \
–with-http_image_filter_module \
–with-http_geoip_module \
–with-http_sub_module \
–with-http_dav_module \
–with-http_flv_module \
–with-http_gzip_static_module \
–with-http_random_index_module \
–with-http_secure_link_module \
–with-http_degradation_module \
–with-http_stub_status_module \
–with-http_perl_module \
–with-perl=which perl \
–with-cpp_test_module \
–with-cpu-opt=pentium4 \
–http-log-path=/usr/local/nginx/log/nginx-access.log \
–http-client-body-temp-path=/usr/local/nginx/tmp/client \
–http-proxy-temp-path=/usr/local/nginx/tmp/proxy \
–http-fastcgi-temp-path=/usr/local/nginx/tmp/fastcgi


[root@localhost nginx-0.8.37]# make


[root@localhost nginx-0.8.37]# make install


디렉토리 생성


[root@localhost nginx-0.8.37]# mkdir /usr/local/nginx/conf



서비스 데몬 작성


[root@localhost nginx-0.8.37]# vi /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' -
   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


[root@localhost nginx-0.8.37]# chmod 755 /etc/rc.d/init.d/nginx



[root@localhost nginx-0.8.37]# vi /usr/local/nginx/conf/nginx.conf



#———————————————————————–#
user  nobody;
pid        log/nginx.pid;
error_log  log/error.log;
#———————————————————————–#
worker_processes  2;
events {
    worker_connections  1024;
#    use kqueue;   # FreeBSD – kqueue
}                       # Linux – epoll
# Syntax: use [ kqueue | rtsig | epoll | /dev/poll | select | poll | eventport ]
#———————————————————————–#


http {
    include       mime.types;
    default_type  application/octet-stream;


    log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
    ‘$status $body_bytes_sent “$http_referer” ‘
    ‘”$http_user_agent” “$http_x_forwarded_for”‘;


    access_log   off;


    ## Size Limits
    client_body_buffer_size   1024m;
    client_max_body_size      1024m;
    client_header_buffer_size 1024m;
    large_client_header_buffers 1 1024m;


    ## Timeouts
    send_timeout          5;
    keepalive_timeout     5 5;
    client_body_timeout   5;
    client_header_timeout 5;


    ## General Options
    sendfile                 on;
    server_tokens           off;
    recursive_error_pages    on;
    ignore_invalid_headers   on;
    server_name_in_redirect  off;
    limit_zone gulag $binary_remote_addr 1m;


    ## TCP options
    tcp_nodelay on;
    tcp_nopush  on;


    ## Compression
    gzip              on;
    gzip_static       on;
    gzip_buffers      16 8k;
    gzip_comp_level   9;
    gzip_http_version 1.0;
    gzip_min_length   0;
    gzip_types        text/plain text/css image/x-icon image/bmp image/png application/x-javascript image/gif;
    gzip_vary         on;


# Virtualhost
server {
        listen       80;
        server_name  nginx1.xinet.kr;
        root   /home/xinet/html/;
        index  index.html index.htm;


        charset utf-8;


        location ~* ^.*\.(ico|css|js|gif|jp?g|png|svg|bmp)\?[0-9]+$ {
           access_log off;
           expires max;
           break;
       }
    }
}



필요한 파일 복사
[root@localhost nginx-0.8.37]# cp /usr/local/nginx/mime.types /usr/local/nginx/conf/


서비스 시작
[root@localhost nginx-0.8.37]# /etc/rc.d/init.d/nginx start
nginx (을)를 시작 중:                                      [  OK 


[root@localhost nginx-0.8.37]# ps -ef | grep nginx
root     17334     1  0 13:44 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   17335 17334  0 13:44 ?        00:00:00 nginx: worker process                                         
nobody   17337 17334  0 13:44 ?        00:00:00 nginx: worker process                                         


웹페이에서 확인






nginx 컴파일 작업시 에러 발생이 될경우
아래 옵션만을 이용한다
./configure –prefix=/usr/local/nginx –conf-path=/usr/local/nginx/nginx.conf –sbin-path=/usr/local/nginx/sbin/nginx –pid-path=/usr/local/nginx/log/nginx.pid –lock-path=/usr/local/nginx/log/nginx.lock –error-log-path=/usr/local/nginx/log/error.log –user=nobody –group=nobody –with-http_ssl_module –with-http_realip_module –with-http_addition_module –with-http_image_filter_module –with-http_geoip_module –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_degradation_module –with-http_stub_status_module –with-http_perl_module –with-perl=/usr/bin/perl –with-cpp_test_module –http-log-path=/usr/local/nginx/log/nginx-access.log –http-client-body-temp-path=/usr/local/nginx/tmp/client –with-cc-opt=”-I /usr/include/pcre”


코멘트 쓰기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.

다음의 HTML 태그와 속성을 사용할 수 있습니다:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



배송정보
배송조회를 하시려면 송장번호를 클릭하세요
배송조회
상품명
주문번호
택배사
송장번호