nginx 설치 ( CentOS 6 )

Posted by 크롱_k
2016.07.19 11:18 서버/리눅스 이야기

Http 서비스를 하기 위한 데몬중 Nginx에 설치에 대한 설명 이다.

 

CentOS 6 에서 진행 했으며, nginx 1.11.2 버전 이다.

 

Nginx 설치


 

 

1. 필수 라이브러리 설치

yum -y install gcc* make libtool-ltdl-devel openssl-devel pcre-devel ncurses-devel

yum -y install libxml2-devel bzip2-devel curl-devel gdbm-devel libjpeg-devel libpng-devel 

yum -y install freetype-devel imap-devel libc-client-devel krb5-devel libmcrypt 

yum -y install libmcrypt-devel libmhash-devel flex icu libicu libicu-devel gd gd-devel libxslt libxslt-devel

 

2. 설치 파일 다운로드

  • 하위 내용을 순차적으로 진행 한다.

 

# cd /usr/local/src

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

# tar zxvf nginx-1.11.2.tar.gz

# cd nginx-1.11.2

# ./configure --prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--sbin-path=/usr/local/nginx/sbin/nginx \
--lock-path=/usr/local/nginx/nginx.lock \
--pid-path=/usr/local/nginx/nginx.pid \
--http-client-body-temp-path=/usr/local/nginx/tmp/body \
--http-proxy-temp-path=/usr/local/nginx/tmp/proxy \
--http-fastcgi-temp-path=/usr/local/nginx/tmp/fastcgi \
--http-uwsgi-temp-path=/usr/local/nginx/tmp/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/tmp/scgi \
--http-log-path=/usr/local/nginx/logs/access.log \
--error-log-path=/usr/local/nginx/logs/error.log \
--with-http_addition_module \
--with-http_degradation_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_realip_module \
--with-http_xslt_module \
--with-http_dav_module \
--with-http_auth_request_module \
--user=nobody \
--group=nobod

 


# make && make install 

 

 3. Nginx start script 작성


# vi /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"
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

#NGINX_CONF_FILE="/etc/nginx/nginx.conf"
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' -`
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


# chmod 700 /etc/init.d/nginx   //  실행 권한을 준다.

# /etc/init.d/nginx start              //  nginx를 실행한다.



 

이 댓글을 비밀 댓글로