nginx配置lua脚本

1.下载对应的安装包 

wget https://luajit.org/download/LuaJIT-2.0.4.tar.gz
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz

我这里也整理了一份(https://download.csdn.net/download/yangyongdehao30/78119103

2.进行安装,记得luajit 要配置环境变量

tar -zxvf LuaJIT-2.0.5.tar.gz

cd LuaJIT-2.0.5

make && make install PREFIX=/usr/local/LuaJIT

vi /etc/profile 加入并使之生效

# lua

export LUAJIT_LIB=/usr/local/LuaJIT/lib

export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0

执行

source /etc/profile

3.增加nginx model编译

./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

lua-nginx-module-0.10.9rc7 和 ngx_devel_kit-0.3.0 替换为自己的路径即可

4. make   --> make install

5.查看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

/usr/local/LuaJIT/lib - 自己的 luaJIT的lib (如果安装luajit时没指定config 则为/usr/local/lib)

如无法启动,提示:[emerg] getpwnam(“www”) failed,则创建用户

/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www

 

6.修改nginx.cnf

location /lua {

        default_type text/html;

        access_by_lua_file /usr/local/nginx/conf/test.lua;

}

test.lua:

ngx.say("111");

请求 http:ip:port/lua 返回 1111

本文参考Nginx 使用Lua脚本 - winss - 博客园

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值