Openresty和Tengine基于 Nginx 的两个衍生版本,某种意义上他们都和淘宝有关系,前者是前淘宝工程师agentzh主导开发的,后者是淘宝的一个开源项目;

Openresty的最大特点是引入了ngx_lua模块,支持使用lua开发插件;

Tengine的特点是融入了因淘宝自身的一些业务带来的新功能;


Tengine 简介

在 Nginx官方版本的基础上增加的一些定制模块如下:

1、支持动态加载模块:通过加载so文件实现,不用再重新编译整个项目了,配置如下:

dso {
load ngx_http_lua_module.so;
load ngx_http_memcached_module.so;
}



2、ngx_proc_daytime_module模块,这个模块允许开一个独立的服务进程,该模块本身并未实现具体的业务逻辑,而是构建了一个TCP Server框架,等待开发者来实现自己的业务;


3、ngx_http_concat_module模块,用于合并多个文件的响应;


4、ngx_http_upstream_session_sticky_module模块,该模块是一个负载均衡模块,通过cookie实现客户端与后端服务器的会话保持, 在一定条件下可以保证同一个客户端访问的都是同一个后端服务器。


5、ngx_http_upstream_check_module模块,用于检查upstream上游服务器的健康状况,如下是一个配置的例子:

upstream cluster1 {
# simple round-robin
server 192.168.0.1:80;
server 192.168.0.2:80;

check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}



6、trim filter模块,用于删除 html,内嵌 javascript 和 css 中的注释以及重复的空白符,例如:

location / {
trim on;
trim_js on;
trim_css on;
}



7、ngx_http_headers_module模块,支持根据Content-Type来设置过期时间,例如:

expires_by_types       24h text/html;
expires_by_types modified +24h text/xml;
expires_by_types @15h30m text/xml;
expires_by_types 0 text/xml;
expires_by_types -1 text/xml;
expires_by_types epoch text/xml;



8、ngx_http_limit_req_module模块,限制访问

9、扩展了ngx_http_log_module模块,支持syslog和pipe;