nginx 가상 호스트 설치

4357 단어 local
nginx 설치
nginx 의존 라 이브 러 리 설치
[root@localhost src]# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.4.4.tar.gz
[root@localhost src]# tar zxvf nginx-1.4.4.tar.gz 
[root@localhost src]# cd nginx-1.4.4
[root@localhost nginx-1.4.4]# ./configure              -- help 보기 옵션 으로 설치 할 수도 있 습 니 다.
[root@localhost nginx-1.4.4]# make
[root@localhost nginx-1.4.4]# make install
설치 완료 후 시작 nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx
스 크 립 트 시작 정지 ngix 설정
아래 셸 스 크 립 트 내용 은 Nginx 의 실제 컴 파일 에 따라 설 치 된 설정 을 수정 해 야 합 니 다.  NGINX_CONF_FILE="/etc/nginx/nginx.conf"  화해시키다  lockfile=/var/lock/nginx.lock  
nginx="/usr/sbin/nginx"       
vim /etc/init.d/nginx  


#! /bin/bash
#nx - 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
# pidfile: /var/run/nginx/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"                // 나의 nginx 경로
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"    // 나의 nginx 경로
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx                           // 나의 nginx 경로
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
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
-------------------------------------------------------------------------------
[root@localhost ~]# chmod +x /etc/init.d/nginx 
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig nginx on
[root@localhost ~]# chkconfig --list | grep nginx
nginx          0: 닫 기 1: 닫 기 2: 사용 하기 3: 사용 하기 4: 사용 하기 5: 사용 하기 6: 닫 기
nginx 가상 호스트 설정
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
server {        listen       80;        server_name  123.com;
접근 기기 의 hosts 파일 에 도 메 인 이름 을 설정 합 니 다.     그리고 123. com 을 방문 하 세 요.

좋은 웹페이지 즐겨찾기