Nginx如何添加lua模块

2023-05-25 14:01:55 nginx 模块 添加

安装 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

只 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 添加 lua 模块

测试:

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

浏览器打开:

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

可以看到 hello, lua!

相关文章