您的位置:首页 > 运维架构 > Nginx

线上Nginx部署实战

2016-03-22 13:20 537 查看
线上Nginx部署实战

版本:

Centos realse 6.5
Nginx-1.6.1

安装NGINX

[root@iZ23lbf4m05Z tools]# yum install openssl-devel pcre-devel -y[root@iZ23lbf4m05Z tools]# groupadd -r nginx[root@iZ23lbf4m05Z tools]# useradd -r -g nginx -s /bin/false -M nginx[root@iZ23lbf4m05Z tools]# wget http://mirrors.sohu.com/nginx/nginx-1.6.1.tar.gz[root@iZ23lbf4m05Z tools]# tar xf nginx-1.6.1.tar.gz[root@iZ23lbf4m05Z conf]# mkdir -p /var/tmp/nginx/client/[root@iZ23lbf4m05Z tools]# cd nginx-1.6.1[root@iZ23lbf4m05Z tools]# ./configure --prefix=/application/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/var/tmp/nginx/client/--http-proxy-temp-path=/var/tmp/nginx/proxy/ --with-pcre[root@iZ23lbf4m05Z tools]# make && make install

NGINX启动脚本

vi /etc/init.d/nginx#!/bin/sh# # nginx - thisscript 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: /application/nginx/conf/nginx.conf # pidfile: /application/nginx/logs/nginx.pid # Source functionlibrary. ./etc/rc.d/init.d/functions # Source networkingconfiguration. ./etc/sysconfig/network # Check thatnetworking is up. ["$NETWORKING" = "no" ] && exit 0 nginx="/application/nginx/sbin/nginx"prog=$(basename$nginx) NGINX_CONF_FILE="/application/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' -` 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  安装 nginx