【问题标题】:How do you install lua-resty-string in openresty docker image?如何在 openresty docker 镜像中安装 lua-resty-string?
【发布时间】:2020-04-02 04:09:36
【问题描述】:

我想在我的 openresty 代码中使用 sha256,所以尝试安装 lua-resty-string

我显然错过了一些其他的包,但不知道是哪些。 lua-resty-string homepage 没有提供我能看到的任何线索。

$ docker run --rm -it openresty/openresty bash
# apt-get update && apt-get install luarocks
# luarocks install lua-resty-string
Installing https://luarocks.org/lua-resty-string-0.09-0.rockspec
lua-resty-string 0.09-0 is now installed in /usr/local (license: )
root@28fe64c51c5a:/# luajit
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/
JIT: ON SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse
> resty_sha256 = require "resty.sha256"
> sha256 = resty_sha256:new()
/usr/local/share/lua/5.1/resty/sha256.lua:41: luajit: undefined symbol: SHA256_Init
stack traceback:
    [C]: in function '__index'
    /usr/local/share/lua/5.1/resty/sha256.lua:41: in function 'new'
    stdin:1: in main chunk
    [C]: at 0x55cd1fdaf250

如果 luarocks 能够正确构建或安装软件,我会更加确信它。

我错过了什么(这次)?

【问题讨论】:

    标签: lua openresty


    【解决方案1】:

    似乎lua-resty-string 包仅在nginx 服务器执行代码时才有效。

    root@62817b2fe1b2:/# ldd `which nginx`
        linux-vdso.so.1 (0x00007ffe3b1db000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa367a81000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa367a60000)
        libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fa367a26000)
        libluajit-5.1.so.2 => /usr/local/openresty/luajit/lib/libluajit-5.1.so.2 (0x00007fa3679a3000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa367820000)
        libpcre.so.1 => /usr/local/openresty/pcre/lib/libpcre.so.1 (0x00007fa3677ad000)
        libssl.so.1.1 => /usr/local/openresty/openssl/lib/libssl.so.1.1 (0x00007fa367739000)
        libcrypto.so.1.1 => /usr/local/openresty/openssl/lib/libcrypto.so.1.1 (0x00007fa3674ad000)
        libz.so.1 => /usr/local/openresty/zlib/lib/libz.so.1 (0x00007fa367490000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa3672cf000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa367c97000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa3672b5000)
    root@62817b2fe1b2:/# nm -D /usr/local/openresty/openssl/lib/libcrypto.so.1.1 | grep SHA256_Init
    00000000001b12a0 T SHA256_Init
    

    并且该库带有 openresty:

    root@62817b2fe1b2:/# dpkg -S /usr/local/openresty/openssl/lib/libcrypto.so.1.1
    openresty-openssl: /usr/local/openresty/openssl/lib/libcrypto.so.1.1
    

    所以我想真正的问题是如何告诉 luajit 加载该库,以便在导入 resty.sha256 时解析 SHA256_Init

    这似乎可以通过ffi 完成:

    local ffi = require("ffi")
    local crypto = ffi.load("/usr/local/openresty/openssl/lib/libcrypto.so.1.1", true)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-19
      • 2021-11-04
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多