nginx lua resty http无主机路由错误

nginx lua resty http无主机路由错误,nginx,lua,openresty,Nginx,Lua,Openresty,我正在尝试使用LuaRestyHTTP发出http请求。 我在中创建了一个简单的get api 我可以使用以下地址提出请求: 然而,当我在nginx中尝试这样做时,我得到了错误没有到主机的路由 我的nginx.conf文件是: worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { lua_package_path "$prefix/lua/?.lua;;"

我正在尝试使用LuaRestyHTTP发出http请求。 我在中创建了一个简单的get api

我可以使用以下地址提出请求:

然而,当我在nginx中尝试这样做时,我得到了错误
没有到主机的路由

我的nginx.conf文件是:

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    lua_package_path "$prefix/lua/?.lua;;";
    server {
        listen 8080;
        location / {
            resolver 8.8.8.8;
            default_type text/html;
            lua_code_cache off; #enables livereload for development
            content_by_lua_file ./lua/test.lua;
        }
    }
}
我的Lua代码是

local http = require "resty.http"
local httpc = http.new()

--local res, err = httpc:request_uri("https://requestb.in/snf2ltsn", {ssl_verify = false,method = "GET" })

      local res, err = httpc:request_uri("https://requestb.in/snf2ltsn", {
        method = "GET",
        headers = {
          ["Content-Type"] = "application/x-www-form-urlencoded",
        }
      })
如何解决此问题? 或者有没有建议在nginx中进行http请求? 有线索吗


PS:在我的Lua代码中有一个注释部分。我还尝试使用该代码发出请求,但什么也没发生。

默认情况下,nginx解析器返回给定域的IPv4和IPv6地址

http模块使用cosocket API

Cosocket的带有域名的连接方法选择了一个随机IP地址,它选择了IPv6地址。您可以通过查看nginx error.log进行检查

很可能IPv6在您的机箱上不起作用

要禁用IPv6 for nginx解析器,请在您的位置内使用以下指令:

resolver 8.8.8.8 ipv6=off;

更改包路径,如下所示:

lua_package_path "$prefix/resty_modules/lualib/?.lua;;";
lua_package_cpath "$prefix/resty_modules/lualib/?.so;;";