Tengine 是 nginx 的分支分支版本,在保持相容的基礎上補上了不少企業級擴充。以下示範在 CentOS 5.5 上從零開始安裝,並把它掛成可用 service 管理的背景服務。
yum -y install gcc gcc-c++ yum -y install pcre-devel yum -y install openssl openssl-devel
PCRE 是 rewrite 規則的必要元件,OpenSSL 則用於 HTTPS,兩者都少了 -devel 套件,configure 階段就會直接失敗。
cd /opt/tools/tengine/plugins/proxy_cache wget https://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz tar zxvf ngx_cache_purge-2.1.tar.gz
不指定目錄,使用預設位置 /usr/local/nginx:
./configure make && make install
指定安裝到 /opt:
./configure --prefix=/opt/tengine/nginx make && make install
指定目錄並載入快取清除模組,同時啟用狀態頁:
./configure \ --add-module=/opt/tools/tengine/plugins/proxy_cache/ngx_cache_purge-2.1 \ --prefix=/opt/servers/tengine/nginx \ --with-http_stub_status_module make && make install
建立 /etc/rc.d/init.d/nginx:
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/opt/servers/tengine/nginx/sbin/nginx
nginx_config=/opt/servers/tengine/nginx/conf/nginx.conf
nginx_pid=/opt/servers/tengine/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginx_pid
}
reload() {
echo -n $"Reloading $prog: "
killproc $nginxd -HUP
RETVAL=$?
echo
}
case "$1" in
start) start ;;
stop) stop ;;
reload) reload ;;
restart) stop; start ;;
status) status $prog; RETVAL=$? ;;
*) echo $"Usage: $prog {start|stop|restart|reload|status|help}"; exit 1 ;;
esac
exit $RETVAL
接著賦權並設定開機自啟:
chmod 775 /etc/rc.d/init.d/nginx chkconfig nginx on /etc/rc.d/init.d/nginx restart service nginx restart
完成後即可用 service nginx start|stop|reload 統一管理,不必再記 -s reload 這類參數。若日後要啟用新的模組,重跑一次 configure 與 make install,再 reload 即可。