Nginx的孪生兄弟Tengine与Openresty

一、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 模块

⽹站中的cssjs等⽂件都是⼩⽂件,单个⽂件⼤⼩⼏k甚⾄⼏个字节,所以⽂件的特点是⼩⽽多,会造成⽹站加载时http请求较多,且⽹络传输时间⽐较短,甚⾄有时候请求时间⽐传输时间还⻓,当公司⽹站中的这类⼩⽂件很多时,⼤量的http请求就会造成传输效率低,影响⽹站的访问速度和客户端体验,这时合并http请求就⾮常有必要了,concat模块就提供了合并⽂件http请求的功能,这个模块由淘宝开发,功能和apachemod_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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值