OpenResty 整合 LuaRocks - Linux

OpenResty LuaRocks Linux About 2,242 words

安装 LuaRocks

下载地址:https://luarocks.github.io/luarocks/releases

下载并解压

wget https://luarocks.github.io/luarocks/releases/luarocks-3.5.0.tar.gz
tar -zxvf luarocks-3.5.0.tar.gz
cd luarocks-3.5.0

配置编译参数

./configure --prefix=/usr/local/openresty/luarocks --with-lua=/usr/local/openresty/luajit/ --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 --with-lua-lib=/usr/local/openresty/lualib

可能出现的错误

找不到unzip命令,执行yum安装即可yum -y install unzip zip

Could not find 'unzip'.
Make sure it is installed and available in your PATH.

configure failed.

正确配置编译参数后输出

Configuring LuaRocks version 3.5.0...

Lua version detected: 5.1
Lua interpreter found: /usr/local/openresty/luajit/bin/luajit
lua.h found: /usr/local/openresty/luajit/include/luajit-2.1/lua.h
unzip found in PATH: /usr/bin

Done configuring.

LuaRocks will be installed at......: /usr/local/openresty/luarocks
LuaRocks will install rocks at.....: /usr/local/openresty/luarocks
LuaRocks configuration directory...: /usr/local/openresty/luarocks/etc/luarocks
Using Lua from.....................: /usr/local/openresty/luajit
Lua include directory..............: /usr/local/openresty/luajit/include/luajit-2.1
Lua lib directory..................: /usr/local/openresty/lualib

* Type make and make install:
  to install to /usr/local/openresty/luarocks as usual.
* Type make bootstrap:
  to install LuaRocks into /usr/local/openresty/luarocks as a rock.

编译

make -j8

安装

使用sudo执行,否则可能会无法创建文件夹。

sudo make install

建立软链

/usr/local/sbin下建立luarocks命令,链接到真实命令/usr/local/openresty/luarocks/bin/luarocks

ln -s /usr/local/openresty/luarocks/bin/luarocks /usr/local/sbin/luarocks

添加 lua 包路径

修改nginx.conf配置文件,在http节点下,添加lua_package_pathlua_package_cpath属性,链接的lua包路径为,LuaRocks配置编译参数阶段指定的--prefix参数对应的文件夹(一般--prefix设置为OpenResty安装的目录下新建luarocks文件夹)。

$prefixOpenResty编译安装时指定的--prefix对应的文件夹,且$prefix只适用于lua_package_path/lua_package_cpath属性。

注意:虽然编译安装时指定的--prefix/usr/local/openresty,但nginx真实的--prefix/usr/local/openresty/nginx,可使用./nginx -V查看,所以设置LuaRocks路径时指定为$prefix/../luarocks

http {
    lua_package_path '$prefix/z_blog_openresty/src/?.lua;$prefix/../luarocks/share/lua/5.1/?.lua;$prefix/../luarocks/share/lua/5.1/?/init.lua;;';
    lua_package_cpath '$prefix/../luarocks/lib/lua/5.1/?.so;;';
}
Views: 3,636 · Posted: 2021-05-04

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh