HAProxy community

HAProxy LUA not able to load LUA module cjson



The LUA with HAproxy is not able to load cjson and LUA execution exits.

> Is there special cjson.so inclusion required in HAProxy config or LUA file?

 local function foo()
        core.log(core.info, "In foo")

        local json = require('cjson')

        core.log(core.info, "Out foo")

function choose_backend(txn)


        return "app"

core.register_fetches("choose_backend", choose_backend)

Only prints below log in HAProxy logs
In foo

frontend http-in
    mode http

    bind *:443 ssl crt /etc/haproxy/server.pem ca-file /etc/haproxy/ca.crt verify required

    **use_backend %[lua.choose_backend]**
    reqadd X-Forwarded-Proto:\ https if { ssl_fc }
    option forwardfor

The same cjson on same centos machine works with standalone lua problem.

$ cat helloworld
-- hello world lua program
print ("Hello World!")

local function foo()
        print ("In foo")

        local json = require('cjson')

        print ("Out foo")


Prints - lua helloworld
Hello World!
In foo
Out foo

The cjson is installed on centos machine

$ rpm -ql lua-cjson



HAProxy sends error log if Lua ends with an error.
These errors are sent on the same way than the proxy logs.

In other way, haproxy requires lua-5.3, your cjson file are compiled with the lua5-1 version.