Nginx添加lua模块的实现方法

这篇文章主要介绍了Nginx添加lua模块的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

安装 lua

 wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz tar -zxvf LuaJIT-2.0.5.tar.gz cd LuaJIT-2.0.5 make && make install PREFIX=/usr/local/LuaJIT 

etc/profile 加入

 # lua export LUAJIT_LIB=/usr/local/LuaJIT/lib export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0 

source etc/profile

下载 ngx_devel_kit 模块

 wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz

NDK (nginx development kit) 模块是一个拓展 nginx 服务器核心功能的模块,第三方模块开发可以基于它来快速实现。 NDK 提供函数和宏处理一些基本任务, 减轻第三方模块开发的代码量

下载 lua-nginx-module 模块

 wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz 

lua-nginx-module 模块使 nginx 中能直接运行 lua

查看原始编译

 nginx -V

如:
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module

进入 nginx 原始目录:

 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module --add-module=/root/lua-nginx-module-0.10.9rc7/ --add-module=/root/ngx_devel_kit-0.3.0

只 make,不执行 make install。

编译报错应该就是 lua 环境变量不对。

 nginx -V 命令报错 ./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory 解决: echo "/usr/local/LuaJIT/lib" >> /etc/ld.so.conf ldconfig 

成功之后可以 nginx -V 查看,无报错即可。

把原来的 nginx 备份为 nginx_old

cp objs/nginx 到原来的 nginx 并覆盖。

在编译目录执行

 make upgrade

Nginx 添加 lua 模块

测试:

 server{ ... location /lua { default_type 'text/html'; content_by_lua ' ngx.say("hello, lua!") '; } ... } 

浏览器打开:

http://blog.13sai.com/lua

可以看到 hello, lua!

以上就是Nginx添加lua模块的实现方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 服务器