我试着用Lua-R校- http提出一个http请求。我在https://requestb.in中创建了一个简单的get api
我可以使用以下地址提出请求:https://requestb.in/snf2ltsn
然而,当我尝试在nginx中这样做时,我得到了错误的no route to host
我的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代码中有一个注释部分。我还试图使用该代码提出请求,但没有发生任何事情。
发布于 2018-01-16 05:05:00
更改package_path如下:
lua_package_path "$prefix/resty_modules/lualib/?.lua;;";
lua_package_cpath "$prefix/resty_modules/lualib/?.so;;";
发布于 2017-10-15 17:18:11
默认情况下,nginx解析器返回给定域的IPv4和IPv6地址。
resty.http模块使用cosocket。
Cosocket的连接方法调用域名,选择一个随机IP地址,你是不幸运的,它选择了IPv6地址。您可以通过查看nginx error.log来检查它。
很可能IPv6不能在你的盒子上工作。
要禁用nginx解析器的IPv6,请在您所在的位置使用下面的指令:
resolver 8.8.8.8 ipv6=off;
https://stackoverflow.com/questions/46745478
复制相似问题