LNMP 시리즈 (1) centos 6.0 nginx 설치

7085 단어
#!/bin/bash
\ # 설치 의존
yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
#zlib:nginx  gzip  ,  zlib   
#openssl:nginx  ssl  
#pcre:      rewrite  

\ # 사용자 만 들 기
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx
id nginx

\ # 로그 디 렉 터 리 만 들 기 
mkdir /var/log/nginx

\ # 다른 디 렉 터 리
mkdir -pv /var/tmp/nginx/{client,proxy,fastcgi}

준비
./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--user=nginx \
--group=nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_mp4_module \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi

#make && make install
make && make install

\ # 경로 검사
ls /usr/local/nginx/
ls /usr/local/nginx/sbin/
ls /etc/nginx/

\ # path 쓰기
echo "export PATH=/usr/local/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh

\ # ngnix 환경 적용
source /etc/profile.d/nginx.sh

\ # nginx 버 전 보기
nginx -v

\ # 테스트 nginx 파일
nginx -t

\ # 설정 서비스
vim /etc/rc.d/init.d/nginx
#             --list
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve

#! /bin/sh
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/etc/nginx/$NAME.conf
PIDFILE=/var/run/nginx/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}

do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac

exit 0

\ # 켜 기 설정 확인
chkconfig --list nginx
chkconfig --add nginx
chkconfig nginx on

\ # 스 크 립 트 권한 설정
chmod +x /etc/rc.d/init.d/nginx

\ # 시작:
/usr/local/nginx/sbin/nginx 

\ # 다시 시작
/usr/local/nginx/sbin/nginx -s reload

\ # 관련 조작
#  nginx     
ps -ef | grep nginx
#     
kill -QUIT      
#     
kill -TERM      
#     
pkill -9 nginx

#     
netstat –na|grep 80
#       
http://ip:80

\ # 맵
location / {
proxy_pass http://localhost:8080/;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Host $host; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
#root html;
#index index.html;
}

location /v1/ {
proxy_pass http://localhost:8080/v1/;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Host $host; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
#root html;
#index index.html;
}

좋은 웹페이지 즐겨찾기