安装 lua
etc/profile 加入
source etc/profile
下载 ngx_devel_kit 模块
NDK (nginx development kit) 模块是一个拓展 nginx 服务器核心功能的模块,第三方模块开发可以基于它来快速实现。 NDK 提供函数和宏处理一些基本任务, 减轻第三方模块开发的代码量
下载 lua-nginx-module 模块
lua-nginx-module 模块使 nginx 中能直接运行 lua
查看原始编译
如:
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.confldconfig成功之后可以 nginx -V 查看,无报错即可。
把原来的 nginx 备份为 nginx_old
cp objs/nginx 到原来的 nginx 并覆盖。
在编译目录执行
make upgradeNginx 添加 lua 模块
测试:
server{ ... location /lua { default_type 'text/html'; content_by_lua ' ngx.say("hello, lua!") '; } ...}浏览器打开:
http://blog.13sai.com/lua
可以看到 hello, lua!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。