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_path
和lua_package_cpath
属性,链接的lua
包路径为,LuaRocks
配置编译参数阶段指定的--prefix
参数对应的文件夹(一般--prefix
设置为OpenResty
安装的目录下新建luarocks
文件夹)。
$prefix
是OpenResty
编译安装时指定的--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;;';
}
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓