'nginx'에 해당되는 글 2건

  1. 2013.01.22 nginx 설치 하기
  2. 2013.01.21 nginx 설치 준비
2013. 1. 22. 00:01

1. nginx 소스 코드 다운로드

http://nginx.com/

http://nginx.org/en/download.html

위 사이트에서 직접 다운로드 받는다.


wget를 이용해도 된다.

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



2. 압축 풀기

# tar xvfz nginx-1.2.6.tar.gz


3. 환경 설정, 컴파일, 설치

# ./configure

# make

# make install


별다른 경로설정 없이 make install을 할 경우, 컴팡리된 파일 등이 /usr/local/nginx 디렉토리로 복사된다.


./configure에서 --prefix 옵션을 통해 기본 경로(/usr/local/nginx)를 변경할 수 있다.


보통 nginx의 버전을 기입한다.

# ./configure --prefix=/usr/local/nginx-1.2.6


default로 conf-path는 <prefix>/conf/nginx.conf, sbin-path는 <prefix>/sbin/nginx 가 된다.


4. apt-get 이용

위 방법 말고 apt-get을 이용하여 쉽게 설치할 수도 있다.

# apt-get update

# apt-get install nginx


이 경우 모듈 설정을 할 수 없다는 단점이 있다. apache의 경우, 설치 이후에 모듈을 추가하거나 설정을 변경할 수 있지만, nginx의 경우 컴파일 전에 모듈을 추가, 설정해야 하기 때문이다.




* 요약 정리

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

# tar xvfz nginx-1.2.6.tar.gz

# ./configure --prefix=/usr/local/nginx-1.2.6 \

--user=www-data --group=www-data \

--with-http_ssl_module \

--with-http_realip_module \

--with-http_xslt_module

(apt-get install libxml2 필요)

(그밖에 pcre, zlib, openssl은 이전 글 참고)

(만약 www-data 사용자가 없을 경우, 추가해줄것. nginx.conf에 user, group가 없는 경우 유효함)


# make && make install

# cd /usr/local/sbin

# ln -s /usr/local/nginx-1.2.6/sbin/nginx nginx

# vim /etc/init.d/nginx        ; /etc/init.d/nginx 스크립트는 밑에 소스 참조

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


작동 테스트

# service nginx start

# service nginx restart

# service nginx stop


만약 service nginx restart가 제대로 작동하지 않는다면, 여기를 참고해서, --pid-path의 경로에서 생성되는 nginx.pid의 위치와, /etc/init.d/nginx에서 PIDSPATH 경로가 일치하는지 확인할 것


시스템 런레벨에서 init스크립트를 실행하기 위해선 다음 명령어 입력

# update-rc.d -f nginx defaults

그러면 우분투가 재시작되어도 nginx가 실행된다.



다음은 /etc/init.d/nginx 스크립트 전문


#! /bin/sh


# 해당 소스는 Jason Giedymin이 최초 작성하였고

# 제가 약간 수정했으며, 한글 주석을 달았습니다.

#

# Author:  Jason Giedymin

#          <jason.giedymin AT gmail.com>.

#

# Version: 2.0 02-NOV-2009 jason.giedymin AT gmail.com

# Notes: nginx init.d dash script for Ubuntu <=9.10.

# This script's project home is:

# http://code.google.com/p/nginx-init-ubuntu/

#

#------------------------------------------------------------------------------

#                               MIT X11 License

#------------------------------------------------------------------------------

#

# Copyright (c) 2009 Jason Giedymin, http://Amuxbit.com formerly

#     http://AcronymLabs.com

#

# Permission is hereby granted, free of charge, to any person obtaining

# a copy of this software and associated documentation files (the

# "Software"), to deal in the Software without restriction, including

# without limitation the rights to use, copy, modify, merge, publish,

# distribute, sublicense, and/or sell copies of the Software, and to

# permit persons to whom the Software is furnished to do so, subject to

# the following conditions:

#

# The above copyright notice and this permission notice shall be

# included in all copies or substantial portions of the Software.

#

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,

# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE

# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION

# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION

# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#------------------------------------------------------------------------------


#------------------------------------------------------------------------------

#                               Functions

#------------------------------------------------------------------------------

. /lib/lsb/init-functions


#------------------------------------------------------------------------------

#                               Consts

#------------------------------------------------------------------------------

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DAEMON=/usr/local/nginx-1.2.6/sbin/nginx  #nginx 파일의 위치


PS="nginx"

PIDNAME="nginx" #lets you do $PS-slave

PIDFILE=$PIDNAME.pid                    #pid file

PIDSPATH=/usr/local/nginx-1.2.6/logs    #nginx.pid가 생성되는, --pid-path로 지정한 경로


DESCRIPTION="Nginx Server..."


RUNAS=root                              #user to run as


SCRIPT_OK=0                             #ala error codes

SCRIPT_ERROR=1                          #ala error codes

TRUE=1                                  #boolean

FALSE=0                                 #boolean


lockfile=/var/lock/subsys/nginx

NGINX_CONF_FILE="/usr/local/nginx-1.2.6/conf/nginx.conf"  #nginx.conf 파일 위치


#------------------------------------------------------------------------------

#                               Simple Tests

#------------------------------------------------------------------------------


#test if nginx is a file and executable

test -x $DAEMON || exit 0


# Include nginx defaults if available

if [ -f /etc/default/nginx ] ; then

        . /etc/default/nginx

fi


#set exit condition

#set -e


#------------------------------------------------------------------------------

#                               Functions

#------------------------------------------------------------------------------


setFilePerms(){


        if [ -f $PIDSPATH/$PIDFILE ]; then

                chmod 400 $PIDSPATH/$PIDFILE

        fi

}


configtest() {

$DAEMON -t -c $NGINX_CONF_FILE

}


getPSCount() {

return `pgrep -f $PS | wc -l`

}


isRunning() {

        if [ $1 ]; then

                pidof_daemon $1

                PID=$?


                if [ $PID -gt 0 ]; then

                        return 1

                else

                        return 0

                fi

        else

                pidof_daemon

                PID=$?


                if [ $PID -gt 0 ]; then

                        return 1

                else

                        return 0

                fi

        fi

}


#courtesy of php-fpm

wait_for_pid () {

        try=0


        while test $try -lt 35 ; do


                case "$1" in

                        'created')

                        if [ -f "$2" ] ; then

                                try=''

                                break

                        fi

                        ;;


                        'removed')

                        if [ ! -f "$2" ] ; then

                                try=''

                                break

                        fi

                        ;;

                esac


                #echo -n .

                try=`expr $try + 1`

                sleep 1

        done

}


status(){

isRunning

isAlive=$?


if [ "${isAlive}" -eq $TRUE ]; then

                echo "$PIDNAME found running with processes:  `pidof $PS`"

        else

                echo "$PIDNAME is NOT running."

        fi



}


removePIDFile(){

if [ $1 ]; then

                if [ -f $1 ]; then

               rm -f $1

       fi

        else

#Do default removal

if [ -f $PIDSPATH/$PIDFILE ]; then

               rm -f $PIDSPATH/$PIDFILE

       fi

        fi

}


start() {

        log_daemon_msg "Starting $DESCRIPTION"

isRunning

isAlive=$?

        if [ "${isAlive}" -eq $TRUE ]; then

                log_end_msg $SCRIPT_ERROR

        else

                start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \

                -- -c $NGINX_CONF_FILE

                setFilePerms

                log_end_msg $SCRIPT_OK

        fi

}


stop() {

log_daemon_msg "Stopping $DESCRIPTION"

isRunning

isAlive=$?

        if [ "${isAlive}" -eq $TRUE ]; then

                start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE


wait_for_pid 'removed' $PIDSPATH/$PIDFILE


                if [ -n "$try" ] ; then

                        log_end_msg $SCRIPT_ERROR

                else

                        removePIDFile

               log_end_msg $SCRIPT_OK

                fi


        else

                log_end_msg $SCRIPT_ERROR

        fi

}


reload() {

configtest || return $?


log_daemon_msg "Reloading (via HUP) $DESCRIPTION"


        isRunning

        if [ $? -eq $TRUE ]; then

`killall -HUP $PS` #to be safe


                log_end_msg $SCRIPT_OK

        else

                log_end_msg $SCRIPT_ERROR

        fi

}


quietupgrade() {

log_daemon_msg "Peforming Quiet Upgrade $DESCRIPTION"


        isRunning

        isAlive=$?

        if [ "${isAlive}" -eq $TRUE ]; then

kill -USR2 `cat $PIDSPATH/$PIDFILE`

kill -WINCH `cat $PIDSPATH/$PIDFILE.oldbin`

isRunning

isAlive=$?

if [ "${isAlive}" -eq $TRUE ]; then

kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`

wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin

                        removePIDFile $PIDSPATH/$PIDFILE.oldbin


log_end_msg $SCRIPT_OK

else

log_end_msg $SCRIPT_ERROR

log_daemon_msg "ERROR! Reverting back to original $DESCRIPTION"


kill -HUP `cat $PIDSPATH/$PIDFILE`

kill -TERM `cat $PIDSPATH/$PIDFILE.oldbin`

kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`


wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin

                        removePIDFile $PIDSPATH/$PIDFILE.oldbin


log_end_msg $SCRIPT_ok

fi

        else

                log_end_msg $SCRIPT_ERROR

        fi

}


terminate() {

        log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"

        

PIDS=`pidof $PS` || true


[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`


for i in $PIDS; do

if [ "$i" = "$PIDS2" ]; then

        kill $i

                        wait_for_pid 'removed' $PIDSPATH/$PIDFILE

removePIDFile

fi

done


log_end_msg $SCRIPT_OK

}


destroy() {

log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION"

killall $PS -q >> /dev/null 2>&1

log_end_msg $SCRIPT_OK

}


pidof_daemon() {

    PIDS=`pidof $PS` || true


    [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`


    for i in $PIDS; do

        if [ "$i" = "$PIDS2" ]; then

            return 1

        fi

    done

    return 0

}


case "$1" in

  start)

start

        ;;

  stop)

stop

        ;;

  restart|force-reload)

stop

sleep 1

start

        ;;

  reload)

$1

;;

  status)

status

;;

  configtest)

        $1

        ;;

  quietupgrade)

$1

;;

  terminate)

$1

;;

  destroy)

$1

;;

  *)

FULLPATH=/etc/init.d/$PS

echo "Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|quietupgrade|terminate|destroy}"

echo "       The 'destroy' command should only be used as a last resort." 

exit 1

;;

esac


exit 0




참고자료

http://blog.blindgaenger.net/create_initd_script_for_nginx.html

http://articles.slicehost.com/2007/10/16/ubuntu-lts-installing-nginx

http://articles.slicehost.com/2007/10/17/ubuntu-lts-adding-an-nginx-init-script

http://stackoverflow.com/questions/8857358/nginx-daemon-stop-is-failing

http://wiki.nginx.org/


Posted by Нуеоп
2013. 1. 21. 23:35

1. gcc 설치

# apt-get install gcc


2. PCRE(Perl Compatible Regular Expression) 설치

# apt-get install libpcre3 lilbpcre3-dev


3. zlib 설치

# apt-get install zlib1g zlib1g-dev        b와 g 사이 숫자 1임에 주의


4. OpenSSL(Open Secure Sockets Layer) 설치

# apt-get install openssl libssl-dev



1~4단계 한번에 설치

# apt-get install gcc

# apt-get install libpcre3 lilbpcre3-dev zlib1g zlib1g-dev openssl libssl-dev

Posted by Нуеоп
이전버튼 1 이전버튼