검색결과 리스트
글
2.0. centOS 7에 NGINX 설치 및 기본 설정
1. centOS에 NGINX 설치.
- 버추얼 박스에서 테스트
- centOS7, NGINX-1.8.0
1.1. 파일 다운로드 폴더 생성
mkdir src && cd src
1.2. 사용자 추가
sudo useradd --shell /sbin/nologin www-data
sudo useradd --shell /usr/sbin/nologin www-data
2. nginx 다운로드 및 압축 해제
-안정화 버전 다운로. (1.8.0)
wget http://nginx.org/download/nginx-1.8.0.tar.gz
-압축해제
tar xvfz nginx-1.8.0.tar.gz
2.1. 선행 요소 설치
sudo yum install gcc
sudo yum install pcre pcre-devel
sudo yum install openssl openssl-devel
sudo yum install zlib zlib-devel
2.3. configure
-압축을 푼 폴더에서
sudo ./configure --user=www-data --group=www-data --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-debug
2.4. sudo make
2.5. sudo make install
2.6. 서비스 등록
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/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
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
-실행권한 설정
sudo chmod +x /etc/iniit.d/nginx
sudo chkconfig nginx on
sudo chkconfig --add nginx
sudo chkconfig --list nginx
- 실행 시 다음과 같이 출력되어야 함.
- nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2.7. 방화벽 등록
-설치
sudo yum install firewalld
systemctl start firewalld
systemctl enable firewalld
-포트 등록
sudo firewall-cmd --permanent --zone=public --add-prot=80/tcp
-방화벽 재시작
sudo firewall-cmd --reload
2.8. NGINX 시작
service nginx start ( stop restart status )
'Information > 리눅스' 카테고리의 다른 글
ubuntu 12.04 에서 eclipse 설치 이후 오류 발생 (0) | 2016.07.20 |
---|---|
1.0. 우분투에 NGINX 설치 (0) | 2016.01.22 |
0.0. 리눅스 설치 및 설정 (0) | 2016.01.22 |