如何将第三方lua库(通过luarocks安装)加载到haproxy中

我正在使用haproxy的Lua API编写将要运行的lua脚本。

我的脚本需要使用socket包,我想在我的机器上安装它。

目前我正在运行Docker,我的Dockerfile如下所示:

FROM haproxy:1.7

RUN apt-get update -y &&  apt-get install curl luarocks -y
RUN luarocks install luasocket

EXPOSE 80 9000

COPY 500error.json.http /etc/haproxy/errorfiles/
COPY hello_world.lua /etc/haproxy/scripts/

我的脚本有下一行:

local http = require('socket.http')

在运行lua解释器时可以正常工作,但在运行haproxy时不行:

[ALERT] 298/104833 (8) : parsing [/usr/local/etc/haproxy/haproxy.cfg:5] : lua runtime error: /etc/haproxy/scripts/hello_world.lua:1: module 'socket.http' not found:

我应该如何正确地将它加载到haproxy中?

点赞
用户5335575
用户5335575

你可以在 require luasocket 模块之前打印 package.pathpackage.cpath 的值。

这些值存储了 Lua 加载库的路径。

2017-11-05 18:48:04