YUMSERV
Published 2019. 5. 27. 21:37
NGINX 소스설치 LINUX/WEB
반응형

1) Nginx란

Nginx는 트래픽이 많은 웹사이트를 위해 확장성을 설계한 비동기 이벤트 기반 구조의 웹서버입니다. NGINX는 EVENT 기반으로 동작하기 때문에 단일 서버에서도 수만개의 동시 연결을 처리할 수 있으며, 아파치보다는 설정이 간단하고, 속도가 빨라 요즘에 많이 Apache 서버에서 Nginx 서버로 바뀌고 있는 추세입니다.

 

2. Nginx 설치

 

설치 환경으로는 CentOS 7.5이며, Yum으로도 설치 가능하나, 소스로 설치 진행하였습니다.

 

1) 필수 패키지 설치

 

# yum -y install gcc* make cmake libxslt* libxml2* ncurses-devel libtool-ltdldevel openssl-devel pcre-devel ncurses-devel libxml2-devel bzip2-devel curl-devel gdbm-devel libjpeg-devel libpng-devel freetype-devel imap-devel libc-clientdevel krb5-devel libmcrypt libmcrypt-devel libmhash-devel flex icu libicu libicu-devel gd gd-devel openldap-devel

 

2) 다운로드

 

# wget http://nginx.org/download/nginx-1.15.2.tar.gz
# tar xvfz nginx-1.15.2.tar.gz
# cd nginx-1.15.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_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=nobody
# make && make install

 

3) 설정


/etc/init.d/nginx 스크립트의 경우 nginx 홈페이지에 내용 참조하면 됩니다.
https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/


# vi /etc/init.d/nginx
아래 내용 추가
# !/bin/bash
#
# 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: /usr/local/nginx/conf/nginx.conf
# config: /usr/local/nginx/sbin/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:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -
if [ -n “$user” ]; then
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
fi
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
# mkdir /usr/local/nginx/tmp
# vi /usr/local/nginx/conf/nginx.conf
아래 내용 주석 해제 후 설정
pid /var/run/nginx.pid;

 

3) 설치 확인

 

# /etc/init.d/nginx start
Starting nginx (via systemctl): [ OK ]
# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 30928/nginx: master

해당 URL에 들어가보면 nginx로 뜨는 것을 확인할 수 있습니다.


반응형

'LINUX > WEB' 카테고리의 다른 글

Cmake 소스설치  (0) 2019.05.27
PHP 모듈 추가  (0) 2019.05.27
PHP 설치 시 에러사항  (1) 2019.05.27
Apache + PHP 에러사항  (0) 2019.05.27
WORDPRESS 설치  (0) 2019.05.27
profile

YUMSERV

@lena04301

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!