一、Tengine
1.1 安装Tengine,替换Nginx
关闭nginx
nginx -s stop
cd /usr/local/src
wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
tar xvf tengine-2.1.2.tar.gz
获取之前Nginx的编译参数
nginx -V
./configure --prefix=/apps/nginx \
--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-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/src/echo-nginx-module \
--with-openssl=/usr/local/src/openssl-1.1.1d
查看Tengine支持的编译参数
#查看Tengine所支持的编译参数
cd /usr/local/src/tengine-2.1.2/
./configure --help
如果编译不支持参数,会报以下错误
删掉Tengine不支持的编译参数
./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 \
--add-module=/usr/local/src/echo-nginx-module
make && make install
可以看到该tengine是基于哪个nginx版本开发的
/apps/tengine-2.1.2/sbin/nginx -V
1.2 动态加载模块
主要功能:这个模块主要是⽤来运⾏时动态加载模块,⽽不⽤每次都要重新编译Tengine
只要将模块编译成动态模块(configure --with-http_xxx_module),再执行make dso_install
动态加载模块的个数限制为128个
如果已经加载的动态模块有修改,那么必须重起Tengine才会⽣效(nginx -s reload),只⽀持HTTP模块
网站:http://tengine.taobao.org/document_cn/dso_cn.html
#原先编译参数
./configure --prefix=/apps/tengine-2.1.2 --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
#安装lua
yum install lua lua-devel
过滤lua模块
./configure --help | grep shared
#在原先编译参数的基础上增加lua模块
./configure --prefix=/apps/tengine-2.1.2 --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_lua_module=shared
make dso_install
#查看动态加载的模块
ll /apps/tengine-2.1.2/modules/ngx_http_lua_module.so
#修改nginx的配置文件
vim /apps/tengine-2.1.2/conf/nginx.conf
dso {
load ngx_http_lua_module.so;
}
#检查配置文件
/apps/tengine-2.1.2/sbin/nginx -t
the configuration file /apps/tengine-2.1.2/conf/nginx.conf syntax is ok
configuration file /apps/tengine-2.1.2/conf/nginx.conf test is successful
#重新加载服务
/apps/tengine-2.1.2/sbin/nginx -s reload
"share"表示编译成动态模块
1.2 concat 模块
⽹站中的css、js等⽂件都是⼩⽂件,单个⽂件⼤⼩⼏k甚⾄⼏个字节,所以⽂件的特点是⼩⽽多,会造成⽹站加载时http请求较多,且⽹络传输时间⽐较短,甚⾄有时候请求时间⽐传输时间还⻓,当公司⽹站中的这类⼩⽂件很多时,⼤量的http请求就会造成传输效率低,影响⽹站的访问速度和客户端体验,这时合并http请求就⾮常有必要了,concat模块就提供了合并⽂件http请求的功能,这个模块由淘宝开发,功能和apache的mod_concat模块类似。
网站:http://tengine.taobao.org/document_cn/http_concat_cn.html
模块:ngx_http_concat_module
编译动态模块参数:--with-http_concat_module=share,参照1.1编译。
location ~* \.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|wmf|js)$ {
root /data/nginx/images1;
index index.html;
concat on;
concat_max_files 20;
}
二、Openresty
nginx -s stop
cd /usr/loacal/scr
wget https://openresty.org/download/openresty-1.19.3.2.tar.gz
tar xvf openresty-1.19.3.2.tar.gz
cd openresty-1.19.3.2
./configure --prefix=/apps/openresty --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-stream --with-stream_ssl_module --with-stream_realip_module
make && make install
ll /apps/openresty/
total 280
drwxr-xr-x 8 root root 4096 Jan 8 08:44 ./
drwxr-xr-x 5 root root 4096 Jan 8 08:44 ../
drwxr-xr-x 2 root root 4096 Jan 8 08:44 bin/
-rw-r--r-- 1 root root 22924 Jan 8 08:44 COPYRIGHT
drwxr-xr-x 6 root root 4096 Jan 8 08:44 luajit/
drwxr-xr-x 6 root root 4096 Jan 8 08:44 lualib/
drwxr-xr-x 6 root root 4096 Jan 8 08:44 nginx/
drwxr-xr-x 47 root root 4096 Jan 8 08:44 pod/
-rw-r--r-- 1 root root 226755 Jan 8 08:44 resty.index
drwxr-xr-x 5 root root 4096 Jan 8 08:44 site/
/apps/openresty/bin/openresty
#配置文件
/apps/openresty/nginx/conf/nginx.conf