首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到模块'resty.http‘:安装了resty

找不到模块'resty.http‘:安装了resty
EN

Stack Overflow用户
提问于 2020-12-23 08:45:51
回答 2查看 3K关注 0票数 1

在使用resty测试示例代码时,我面临一个问题。请查找相关命令的输出:

代码语言:javascript
复制
$ which resty
/usr/local/bin/resty
$ which openresty
/usr/local/bin/openresty
$ resty -e 'ngx.say("hello world")'               
hello world

文件: test.lua

代码语言:javascript
复制
local http = require "resty.http"
local httpc = http.new()
local res, err = httpc:request_uri("http://example.com/helloworld", {
  method = "POST",
  body = "a=1&b=2",
  headers = {
    ["Content-Type"] = "application/x-www-form-urlencoded",
  },
  keepalive_timeout = 60000,
  keepalive_pool = 10
})

if not res then
  ngx.say("failed to request: ", err)
  return
end

在使用resty运行这个test.lua文件时,我面临的是模块'resty.http‘没有找到:

代码语言:javascript
复制
$ resty test.lua                                    
ERROR: test.lua:1: module 'resty.http' not found:
        no field package.preload['resty.http']
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http.ljbc'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http/init.ljbc'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.ljbc'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http/init.ljbc'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http.lua'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http/init.lua'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.lua'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http/init.lua'
        no file './resty/http.lua'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/share/luajit-2.1.0-beta3/resty/http.lua'
        no file '/usr/local/share/lua/5.1/resty/http.lua'
        no file '/usr/local/share/lua/5.1/resty/http/init.lua'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/share/lua/5.1/resty/http.lua'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/share/lua/5.1/resty/http/init.lua'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http.so'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.so'
        no file './resty/http.so'
        no file '/usr/local/lib/lua/5.1/resty/http.so'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/lib/lua/5.1/resty/http.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty.so'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty.so'
        no file './resty.so'
        no file '/usr/local/lib/lua/5.1/resty.so'
        no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/lib/lua/5.1/resty.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        test.lua:1: in function 'file_gen'
        init_worker_by_lua:45: in function <init_worker_by_lua:43>
        [C]: in function 'xpcall'
        init_worker_by_lua:52: in function <init_worker_by_lua:50>

我也试过Install resty.http with already installed openresty

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-12-23 11:22:25

我使用Install resty.http with already installed openresty中提到的相同的解决方案来解决这个问题。

第一次,这对我不起作用,因为我有一条神圣的道路。但是,当我检查错误日志时,我知道它正在/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.lua寻找/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.lua,所以复制https://github.com/ledgetech/lua-resty-http/blob/master/lib/resty/http.lua对我有用。

感谢Alexander Altshuleroriginal answer

票数 0
EN

Stack Overflow用户

发布于 2021-01-06 07:17:12

那家图书馆默认带有空。不要复制文件,而是使用LUA_PATH环境变量调整Lua路径设置。这可以使用LuaRocks完成(默认情况下还包括空)

若要使用LuaRocks设置路径,请尝试:

代码语言:javascript
复制
eval `luarocks path`
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65421374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档