Pages

9/05/2013

install nginx(Centos)

nginx 설정이 apache보다 쉽고(개인적으로...콜록) 성능도 더 좋은(잘 느끼진 못하지만^^;) nginx설치 방법을 정리해보겠다. mac을 좋아하지만 개발할때 많이 사용하는 centos를 기준으로 정리해보겠다.

설치방법은 간단하다. 우선 다운 받고 압축을 푼다.

wget http://nginx.org/download/nginx-1.5.4.tar.gz
tar -xzvf nginx-1.5.4.tar.gz
압축 풀고 make / make install 하면 끝난다. make 하기전에 gcc, make 등 필요한 것들을 먼저 install 한다.
yum install gcc gcc-c++ make autoconf wget libxml2-devel perl perl-devel perl-ExtUtils-*  pcre-devel openssl-devel zlib library cpan
난 yum을 좋아한다...콜록 prefix와 module을 설정하고 make/make install
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-mail_ssl_module --with-http_mp4_module --with-mail
make
make install
다음은 실행 파일을 만들어 준다. 그래야 편하다...
vi /etc/init.d/nginx
붙여넣긔!!!
#!/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: "
$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
service nginx start
service nginx stop
이상!!! 콜록....

1 개의 댓글: