笔记搬到博客 - nginx一步步集成lua模块

经过网络搜索、整理、实践笔记

前置条件:已安装nginx

一 、安装LuaJit

1.下载LuaJit  http://luajit.org/download.html

[duanwc@CentOS_6 source]$ wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz

2.安装

2.1解压:

[duanwc@CentOS_6 source]$ tar -zxvf LuaJIT-2.0.5.tar.gz

2.2进入解压目录

[duanwc@CentOS_6 source]$ cd LuaJIT-2.0.5

2.3编译

[duanwc@CentOS_6 LuaJIT-2.0.5]$ make PREFIX=/data/servers/luajit

2.4完成安装

[duanwc@CentOS_6 LuaJIT-2.0.5]$ make install PREFIX=/data/servers/luajit

二、下载ngx_devel_kit (NDK) 

1.下载 ngx_devel_kit (NDK)   https://github.com/simpl/ngx_devel_kit/tags

[duanwc@CentOS_6 source]$ wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.0.tar.gz

2.解压

[duanwc@CentOS_6 source]$ tar -zxvf v0.3.0.tar.gz

解压后文件夹:ngx_devel_kit-0.3.0

三、下载 ngx_lua

1.下载 ngx_lua  https://github.com/openresty/lua-nginx-module/tags

[duanwc@CentOS_6 source]$ wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz

2.解压

[duanwc@CentOS_6 source]$ tar -zxvf v0.10.13.tar.gz

解压后文件夹:lua-nginx-module-0.10.13

四、查看之前编译参数

[duanwc@CentOS_6 source]$ nginx -V

configure arguments: --prefix=/data/servers/nginx --with-http_ssl_module --with-http_stub_status_module --with-openssl=/data/source/openssl-1.1.0c --with-threads

五、集成

1. 进入nginx安装源目录

[duanwc@CentOS_6 source]$ cd /data/servers/nginx-1.14.1/

2. 先执行环境变量

[duanwc@CentOS_6 nginx-1.14.1]$ export LUAJIT_LIB=/data/servers/luajit/lib

[duanwc@CentOS_6 nginx-1.14.1]$ export LUAJIT_INC=/data/servers/luajit/include/luajit-2.0

3. 备份之前的nginx

[duanwc@CentOS_6 nginx-1.14.1]$ cp /data/servers/nginx/sbin/nginx /data/servers/nginx/sbin/nginx.bak

4. 编译nginx 增加之前ngxin -V检查的参数

[duanwc@CentOS_6 nginx-1.14.1]$ ./configure --prefix=/data/servers/nginx --with-http_ssl_module --with-http_stub_status_module --with-openssl=/data/source/openssl-1.1.0c --with-threads --add-module=/data/source/ngx_devel_kit-0.3.0/ --add-module=/data/source/lua-nginx-module-0.10.13/

[duanwc@CentOS_6 nginx-1.14.1]$ make -j2 //使用2个线程执行

[duanwc@CentOS_6 nginx-1.14.1]$ make install

5. 如启动nginx产生错误

nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

将libluajit-5.1.so.2软链至/lib64下

[duanwc@CentOS_6 ~]$ sudo ln -s /data/servers/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

六、检查lua是否集成成功

1. 打开../conf/nginx.conf配置文件,增加以下配置

location /hello_lua {

default_type 'text/plain';

content_by_lua 'ngx.say("hello, lua")';

}

2.重启nginx

[duanwc@CentOS_6 conf]$ sudo nginx -s reload

3.访问测试页

访问localhost/hello_lua会出现”hello, lua”表示安装成功

七、集成redis - 测试通过后补录

【强烈推荐!非广告!】阿里云双11褥羊毛活动(10.29-11.12):https://m.aliyun.com/act/team1111?from=singlemessage&isappinstalled=0#/share?params=N.FF7yxCciiM.5rnfefip。新用 。新用户低至一折购买【1核2GIM1年99元,2年199元,3年298元】【2核4GIM1年545元,2年927元,3年1227元】【2核8G5M3年2070元】,建议购买两核的服务器,1核的服务器CPU使用率会有限制。老用户可以加入我的战队,然后分享自己的链接,可以获得红包和25%的返现,我们的战队目前1000多位新人,目前排名第2,后面可以瓜分百万现金(按拉新人数瓜分现金,拉的越多分的越多!不要自己重新开战队,后面不能参与瓜分现金)。

猜你喜欢

转载自blog.csdn.net/sbdwtg00/article/details/83893401