Nginx 설치 및 사용법

오랜만에(..처음인가?;) 뭔가 생산적인 포스팅을 해보려고 적어본다!
(사실은 안잊기 위해서 라는……)

서버는 우분투 10.04 LTS 환경이다.

1. Nginx 설치

apt-get install nginx
/etc/init.d/nginx start

간단하게는 이렇게만 하면 설치 완료!;

2. PHP(FastCGI) 설치

apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-recode php5-snmp php5-sqlite php5-xmlrpc php5-xsl spawn-fcgi

이제 php는 설치 완료!

3. Nginx 와 PHP(FastCGI) 연동하기

일단 FastCGI를 실행하기 위한 init스크립트를 작성해야 한다.

# vi /etc/init.d/php-fastcgi

#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-fastcgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description:       Start and stop php-cgi in external FASTCGI mode
### END INIT INFO
 
 
# Author: Kurt Zankl <[EMAIL PROTECTED]>
 
 
# Do NOT "set -e"
 
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="php-cgi in external FASTCGI mode"
NAME=php-fastcgi
DAEMON=/usr/bin/php-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
PHP_CONFIG_FILE=/etc/php5/cgi/php.ini
 
 
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
 
 
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 
 
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
 
 
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
 
 
# If the daemon is not enabled, give the user a warning and then exit,
# unless we are stopping the daemon
if [ "$START" != "yes" -a "$1" != "stop" ]; then
        log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set START=yes"
        exit 0
fi
 
 
# Process configuration
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT -c $PHP_CONFIG_FILE"
 
 
do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
                --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
}
 
 
do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE > /dev/null # --name $DAEMON
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
        [ "$?" = 2 ] && return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return "$RETVAL"
}
case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  restart|force-reload)
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 3
        ;;
esac

init 스크립트를 실행하기 위해 실행 권한을 부여한다.
#chmod 755 /etc/init.d/php-fastcgi

이제 init script 설정 파일 추가한다

#vi /etc/default/php-fastcgi

START=yes
 
# Which user runs PHP? (default: www-data)
 
EXEC_AS_USER=www-data
 
# Host and TCP port for FASTCGI-Listener (default: localhost:9000)
 
FCGI_HOST=localhost
FCGI_PORT=9000
 
# Environment variables, which are processed by PHP
 
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000

이제 Nginx랑 PHP(FastCGI)를 연결시켜줘야 한다.

# vi /etc/nginx/sites-available/default

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default$fastcgi_script_name;
    include fastcgi_params;
}

마지막으로 Nginx 및 FastCGI를 재실행해준다.
/etc/init.d/nginx restart
/etc/init.d/php-fastcgi restart

4. 테스트!
간단하게 test.php 파일을 만들어 본다.

<? php
phpinfo();
?>

http://주소/test.php 로 접속해서 php정보가 요란하게 뜨면 제대로 설정완료.

서버이전 및 wordpress로 이전!

여행을 갔다와서.. 열심히 포스팅을 하지는 않지만 몇가지를 좀 올려보려고 했었다.

근데 가상서버호스팅을 너무 싼걸로 해서 그런지.. 하드용량은 남아도는데 메모리가 부족한 상황!

textcube도 간신히 돌아가고 wordpress는 올리면 뭐.. 걍 바로 뻗어버리는 상황이었다.

그래서 포스팅도 안하고 걍 딩가~딩가~ 놀다가 급 갑자기 필 받아서 좀 만져보려고 했는데

어차피 가상서버호스팅 업글할꺼.. 심심한데 다른곳에서 함 해볼까? 란 생각이들어;;;

급 가상서버호스팅을 변경했다. 뭐 기존에 사용하던 just4fun도 좋았는데.. 그냥 변덕을 좀 부려봤다.

이번에 옮긴 곳은 hostple.net

지난번엔 제일 저렴한 가격의 128MB의 메모리였지만 이번엔 512MB짜리 가상서버호스팅을 신청.

변덕이 정점을 찍어서.. 웹서버도 apache에서 nginx로 바꾸고 블로그툴도 textcube에서 wordpress로 변경!

넓은 메모리라서 그런건지… 좀 더 가볍다는 nginx라서 그런건지.. 매우 빠르고 쾌적하다! 냐하하~

네임서버 변경하고 얼마 안되서 그런지 아직 접속이 조금 불안정하기는 한데.. 이건 좀 지켜봐야할거 같다.

워낙 textcube에 익숙해져 있어서 wordpress에 적응하려면 좀 시간이 걸릴것 같지만..

플러그인이나 테마도 관리자화면에서 검색 및 업데이트도 가능하고 이래저래 편리한거 같다.

서버도 쾌적해졌고.. 블로그툴도 바꿨으니.. 폭풍포스팅!!을 해보고 싶지만.. 과연..???

안경을 맞추다.

마드리드에서 돌아올때 눈이 살짝 부어있기도 했고..
왼쪽 눈이 좀 흐릿하기도 하고..
눈 검사 한지도 오래되어서 찾아간 안과.

“눈이 안좋은데.. 안경 안썼어요?”

..!!

안경을 쓰고 다녀야 할 정도는 아닌거 같았는데..
난시성 원시라나.. 게다가 왼쪽, 오른쪽이 많이 다르다고..

몇년 전 맞춰놓은 안경이 있었지만 가~끔 피곤할때만 썼었는데..
가능하면 평상시에도 쓰고 지내란다.
나중에 나이들면 더 힘들어질지도 모르니 관리 잘하라고 =0=;;;

덕분에 오랜만에 안경점에서 가서 안경을 맞췄다.
눈이 안좋아지긴 했는지.. 일명 압축렌즈라고 부르는 굴절률이 좋은 렌즈를 써야된단다;;
덕분에 가격 급상승! ㅠ_ㅜ

써보니 확실히 선명하고 좋기는 하네…
원시라서 돋보기를 써서 그런지 조금 더 큼직하게도 보이고;;;

한때 눈이 0.6~0.7 이러다가.. 언젠가 급 1.0으로 회복이 되었던 적이 있어서..
그냥 눈은 별 걱정 없이 살았었는데 이젠 조금씩 신경을 써줘야 겠다.

맨날 끼고 다니는건 아직 불편해서 못하겠지만 책이나 컴퓨터할때는 꼭 써줘야지..
렌즈값이 얼만데…-_-