安装tengine
1、依赖gcc openssl-devel pcre-devel zlib-devel
安装:yum install gcc openssl-devel pcre-devel zlib-devel
2、解压tengine压缩包,并进入目录;
3、./configure --prefix=/usr/tengine
4、make && make install
5、将编译完成的tengine作为Linux的系统service进行管理,需要编写一个脚本,将其加入/etc/init.d目录下。
脚本名为nginx。内容如下:
#!/bin/bash
#
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# Source function library.
. /etc/rc.d/init.d/functions# Source networking configuration.
. /etc/sysconfig/network# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0nginx="/usr/tengine/sbin/nginx"
prog=$(basename $nginx)NGINX_CONF_FILE="/usr/tengine/conf/nginx.conf"#[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/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_dirsecho -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval
}stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval
}restart() {configtest || return $?stopsleep 1start
}reload() {configtest || return $?echo -n $"Reloading $prog: "
# -HUP是nginx平滑重启参数 killproc $nginx -HUPRETVAL=$?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" instart)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
执行命令 chmod 755 nginx
6、service nginx start
7、chkconfig --add nginx
chkconfig --list nginx //查看nginx服务状态
chkconfig nginx on //开机自启
配置tengine
/etc/tengine/conf
worker_processes 进程数,与CPU核数相等
events下的worker_connection 一个进程最大支持的并发数
虚拟主机的三种方法:
1、基于ip的虚拟主机,一块主机网卡绑定多个IP地址。
一个网卡可以绑定多个虚拟IP
# ifconfig eth0:1 192.168.143.139 netmask 255.255.255.0
# ifconfig eth0:1 down 停掉
server
{listen 192.168.143.132:80;server_name www.abc.com;
}server
{listen 192.168.143.139:80;server_name www.abc.com;
}
2、基于域名的虚拟主机(servername)
server
{listen 80;server_name www.abc.com;
}server
{listen 80;server_name www.bcd.com;
}
3、基于端口的虚拟主机
server
{listen 80;server_name www.abc.com;
}server
{listen 8080;server_name www.abc.com;
}