所以我想从中加载用C编写的库
content_by_lua_block
.
这是我的
nginx.conf
:
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua_block {
local ffi = require("ffi")
local lib = ffi.load("ffi_example5")
// do smth here...
}
}
}
}
ffi_example5.c
:
int get_value() {
return 5;
}
我是如何编译和运行这一切的。
run_server.sh
:
#!/bin/bash
set -ueo pipefail
mkdir -p logs
export PATH=/usr/local/openresty/nginx/sbin:$PATH
gcc -fPIC -c -o scripts/ffi_example5.o scripts/ffi_example5.c
gcc -shared -Wl,-soname,/usr/local/lib/libffi_example5.so -o /usr/local/lib/libffi_example5.so scripts/ffi_example5.o
nginx -s reload -c conf/nginx.conf
项目结构:
./run_server.sh
conf/:
nginx.conf
scripts/:
ffi_example5.c
以及我的日志错误:
2023/07/29 18:49:37 [error] 97686#0: *361 lua entry thread aborted: runtime error: content_by_lua(nginx.conf:16):3: libffi_example5.so: cannot open shared object file: No such file or directory
stack traceback:
coroutine 0:
[C]: in function 'load'
content_by_lua(nginx.conf:16):3: in main chunk, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
我已经尝试过:
-
背景
LD_LIBRARY_PATH
:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:.
-
正在添加
include /usr/local/lib
到
/etc/ld.so.conf
-
跑
ldconfig
-
离开
lib[libraryname].so
在一个
conf/
目录(其中
nginx.conf
位于),并将其放置在
/usr/local/lib
没有帮助