CentOS 6.5安装配置Tengine
一、安装pcre:
cd /usr/local/src
wget
tar zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure --prefix=/usr/local/pcre
make
make install
二、下载proxy_cache插件
cd /usr/local/src
wget
tar zxvf ngx_cache_purge-2.1.tar.gz 三、安装tengine
yum install openssl openssl-devel -y
cd /usr/local/src
wget
tar zxvf tengine-2.0.0.tar.gz
cd tengine-2.0.0
./configure --add-module=/usr/local/src/ngx_cache_purge-2.1 --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.34
make
make install
/usr/local/nginx/sbin/nginx #启动nginx
chown nobody.nobody -R /usr/local/nginx/html
chmod 700 -R /usr/local/nginx/html如果编译的问题的话,看看是不是下面的原因:
./configure: error: the HTTP SSL module requires OpenSSL library
原因:安装http_ssl_module模块需要openssl library
解决:yum install openssl-devel
./configure: error: the HTTP rewrite module requires the PCRE library.
原因:安装http_rewrite_module模块需要先安装PCRE开发包
解决:yum install pcre-devel
注意:
--with-pcre=/usr/local/src/pcre-8.21指向的是源码包解压的路径,而不是安装的路径,否则会报错。
--add-module=/usr/local/src/ngx_cache_purge-2.1 是指加载缓存的插件模块
四、设置Tengine开机启动
vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容
#!/bin/bash
# Tengine Startup script# processname: nginx
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "tengine 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 nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
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 --level 012345 nginx on #设置开机启动
/etc/rc.d/init.d/nginx restart 四、配置Tengine
将nginx初始配置文件备份,我们要重新创建配置文件.
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
创建nginx用户www
groupadd www
useradd -g www www编辑主配置文件:
vi /usr/local/nginx/conf/nginx.conf内容如下:
user www www;
worker_processes 4; # 工作进程数,为CPU的核心数或者两倍
error_log logs/error.log crit; # debug|info|notice|warn|error|crit
pid logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events {
use epoll; #Linux最常用支持大并发的事件触发机制
worker_connections 65535;
}
http {
include mime.types; #设定mime类型,类型由mime.type文件定义
default_type application/octet-stream;
charset utf-8;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
#设定请求缓冲
server_names_hash_bucket_size 256; #增加,原为128
client_header_buffer_size 256k; #增加,原为32k
large_client_header_buffers 4 256k; #增加,原为32k
#size limits
client_max_body_size 50m; #允许客户端请求的最大的单个文件字节数
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;