tengine,它在Nginx的基础


tengine

tengine简介

  • Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。

  • Tengine使用:http://tengine.taobao.org/

  • tengine使用注意事项1:主要明白当前的tengine版本是基于哪个版本的nginx做的二次研发(nginx版本不同,支持的功能特性不同)。

  • tengine使用注意事项2:tengine的主要使用版本应为:稳定版正式发布

tengine的安装

此处编译安装版本:tengine-2.1.2(基于nginx/1.6.2的二次研发)

  • 编译安装:与nginx无多大差异

①获取源码包:

  • wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
  • 说明:源码包放置路径:/usr/local/src

②解压缩:

  • tar xf tengine-2.1.2.tar.gz

③查看安装说明:

  • vim README
To install Tengine, just follow these three steps:
    $ ./configure
    $ make
    # make install

④./configure

  • 检查编译环境:yum install gcc openssl-devel pcre-devel
  • 生成Makefile文件:
  • 编译选项:./configure --prefix=/apps/tengine --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

⑤make

  • 根据Makefile生成指定模块

⑥make install

  • copy 模块到指定目录

⑦创建nginx用户

  • useradd nginx -s /sbin/nologin -u 2000

⑧修改配置文件

  • vim /apps/tengine/conf/nginx.conf
    user nginx;

⑨启动tengine

  • /apps/tengine/sbin/nginx
  • cp /apps/nginx/sbin/nginx /usr/local/bin/(将nginx程序加入至PATH环境变量)

⑩版本查看:

  • nginx -V
    Tengine version: Tengine/2.1.2 (nginx/1.6.2)
  • 基于(nginx/1.6.2)版本二次研发,不支持upstream相关编译选项

测试主页:

  • curl 192.168.38.27
    192.168.38.27 tengine page

tengine新特性之concat模块

①concat模块的功能:concat模块就提供了合并文件http请求的功能

  • 合并资源的URI:http://192.168.38.27/css/??a.css,b.css,c.css
  • 可以使用??然后同时请求多个资源文件

②concat模块的作用:

  • 此功能的作用:
    网站中的css、js等文件都是小文件,单个文件大小几k甚至几个字节,所以文件的特点是小而多,会造成网站加载时http请求较多,且网络传输时间比较短,甚至有时候请求时间比传输时间还长,当公司网站中的这类小文件很多时,大量的http请求就会造成传输效率低,影响网站的访问速度和客户端体验,这时合并http请求就非常有必要。

③再刚才编译安装的tengine加入concat模块

  • 两种方式: --with-http_concat_module和–with-http_concat_module=shared
    a.暂停tengine服务重新编译安装(此处不暂停tengine服务,暂停服务会影响用户访问)
    b.通过动态模块实现concat功能(此处详述的动态模块功能)

④以动态模块的方式实现concat

  • –with-http_concat_module=shared
  • tengine主机:192.168.38.27
  • 测试主机:192.168.38.37
a.安装lua和lua-devel
#yum install lua lua-devel


b../configure
# ./configure  --prefix=/apps/tengine --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-http_concat_module=shared --with-http_lua_module=shared


c.生成模块
# make dso_install
    ==> /apps/tengine/modules/此目录将生成concat和lua模块


d.配置文件中调用concat和lua模块
dso {
        load ngx_http_lua_module.so; 
        load ngx_http_concat_module.so; 
}


e.在server的location中启用concat模块功能
server {
	listen 80;
	servername www.rootzcp.com;
	
	location /js {
		root html;
		index index.html; 
		concat on;  #启用concat模块功能
	}
}

f.重新加载tengine
# nginx -t
# nginx -s reload


g.准备js文件:
[root@centos7-27 js]# ll /apps/tengine/html/js
-rw-r--r-- 1 root root 101 Nov  4 12:34 a.js
-rw-r--r-- 1 root root 101 Nov  4 12:34 b.js


h.测试:
[root@centos7-37 ~]# curl http://www.rootzcp.com/js/??a.js,b.js
 /apps/tengine/html/js/a.js
 /apps/tengine/html/js/b.js
    不会写js程序----
可见可以支持同时多个资源请求,直接默认是不支持concat功能的哈~~

相关内容